<html ng-app="demoapp">
<head>
<script type="text/javascript" src="../angular.min.js"></script>
<script type="text/javascript">
var demoapp = angular.module('demoapp', []);
demoapp.controller('SimpleController',function ($scope){
$scope.customer = [
{name: "Deepak" , city: "Bhubaneswar"},
{name: "Sivaji" , city: "Banglore"}
];
$scope.addCustomer = function($scope){
$scope.customer.push({ name: $scope.newCustomer.name ,city: $scope.newCustomer.city});
}
});
demoapp.config(function ($routeProvider){
$routeProvider
.when('/',{
controller: 'SimpleController',
templateUrl: 'Partials/view1.html'
})
.when('/view2',{
controller: 'SimpleController',
templateUrl: 'Partials/view2.html'
})
.otherwise({redirectTo: '/'});
});
</script>
</head>
<body>
<div ng-view=""></div>
</body>
请问我这里出了什么问题?为什么我会收到错误。我是Angular的新手请帮忙。我认为配置部分存在一些问题。但是我无法调试它。
答案 0 :(得分:6)
添加角度路线脚本
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.min.js"></script>
添加ngRoute作为依赖
var demoapp = angular.module('demoapp', ["ngRoute"]);
您应该像这样定义控制器。
demoapp.controller('SimpleController',["$scope", function ($scope){
$scope.customer = [
{name: "Deepak" , city: "Bhubaneswar"},
{name: "Sivaji" , city: "Banglore"}
];
$scope.addCustomer = function($scope){
$scope.customer.push({ name: $scope.newCustomer.name ,city: $scope.newCustomer.city});
}
}]);