我不确定为什么路由不起作用。View1.html 包含一个简单的网页,view2.html 也是如此。view1.html 和 view2.html 都位于名为 partials 的文件夹中,而“angular-route.js”和“angular-route.min.js”位于主文件夹中名为 node_modules 的文件夹中。我正在使用 ubuntu 14.04。
<script src="scripts/angular.min.js"></script>
<script src="/node_modules/angular-route/angular-route.js"></script>
<script src="/node_modules/angular-route/angular-route.min.js"></script>
<script>
var demoApp = angular.module('demoApp', ['ngRoute']);
demoApp.config( function ($routeProvider) {
$routeProvider
.when('/',
{
controller: 'SimpleController' ,
templateUrl: 'partials/view1.html' //
})
.when('/view2',
{
controller: 'SimpleController' ,
templateUrl: 'partials/view2.html'
})
.otherwise({ redirectTo : '/' })
})
demoApp.controller('SimpleController', function ($scope)
{
$scope.customers = [{name:'nihal',city:'hyderabad'},{name:'nihal',city:'mumbai'}, {name:'john',city:'bangalore'}]
$scope.addCustomer = function() {
$scope.customers.push({name: newCustomer.name , city: newCustomer.city })
}
})
</script>
</body>
</html>