javascript - AngularJS Routed Page Not Showing -
so quick question i've been looking @ code awhile cannot find why, gives me output on page
partials/view1.html i'm not trying post here whenever run small issue has been baffling me awhile now, , no errors on console. run code http://plnkr.co/edit/sn9tagvbodx3mkrxatiu?p=preview, mentioned on post , works fine, don't right output this. following index.html (the main page)
<!doctype html> <html ng-app="demoapp"> <head> </head> <body> <div ng-view></div> <script src="angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script> <script src="scripts.js"></script> </body> my script likes:
var demoapp = angular.module('demoapp', ['ngroute']); demoapp.config(function($routeprovider) { $routeprovider .when('/', { controller: 'simplecontroller', template: 'partials/view1.html' }) .when('/partial2', { controller: 'simplecontroller', template: 'partials/view2.html' }) .otherwise({ redirectto: '/'}); } ); demoapp.controller('simplecontroller', function ($scope) { $scope.customers = [ {name: 'john smith', city: 'phoenix'}, {name: 'jane doe', city: 'new york'}, {name: 'john doe', city: 'san francisco'} ]; $scope.addcustomer = function() { $scope.customers.push({ name: $scope.newcustomer.name, city: $scope.newcustomer.city }); } }); and don't supposed shown view1.html, showed above. code
<div class="container"> <h2>view 1</h2> name: <br> <input type="text" ng-model="filter.name"> <br> <ul> <li ng-repeat="cust in customers | filter:filter.name | orderby: 'city'">{{ cust.name }} - {{ cust.city }}</li> </ul> <br> customer name: <br> <input type="text" ng-model="newcustomer.name"> customer city: <br> <input type="text" ng-model="newcustomer.city"> <br> <button ng-click="addcustomer()">add customer</button> <br> <a href="#/view2">view 2</a> </div>
you should using templateurl instead of template:
.when('/partial2', { controller: 'simplecontroller', templateurl: 'partials/view2.html' }) https://docs.angularjs.org/api/ngroute/provider/$routeprovider
Comments
Post a Comment