<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>
Could any please suggest me what going wrong here?Why I am getting error. I am newbie to Angular please help. I think there is some issue with the config portion. But I am not able to debug it.
Add angular-route script
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.min.js"></script>
Add ngRoute as dependency
var demoapp = angular.module('demoapp', ["ngRoute"]);
You should define controller like this.
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});
}
}]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With