-
Notifications
You must be signed in to change notification settings - Fork 0
/
first.html
51 lines (48 loc) · 1.54 KB
/
first.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<html data-ng-app="myMod">
<head>
<title>XYZ</title>
</head>
<body>
<div>
<div data-ng-view=""></div>
</div>
<script src="scripts/angular.min.js"></script>
<script src="scripts/angular-route.min.js"></script>
<script>
var mod = angular.module('myMod', ['ngRoute'])
.factory('simpleFactory', function () {
var factory = {};
factory.getResidents = function () {
return [
{ fname: 'Michael', city: 'Mill Valley' },
{ fname: 'Chris', city: 'Sao Paolo' },
{ fname: 'Milan', city: 'Milano' }
];
};
return factory;
})
.controller({
SimpleController: function ($scope, simpleFactory) {
(function init() {
$scope.residents = simpleFactory.getResidents();
})();
$scope.addResident = function () {
$scope.residents.push({ fname: $scope.newResident.name, city: $scope.newResident.city });
};
}
})
.config(function ($routeProvider) {
$routeProvider
.when('/view1', {
controller: 'SimpleController',
templateUrl: 'partials/view1.html'
})
.when('/view2', {
controller: 'SimpleController',
templateUrl: 'partials/view2.html'
})
.otherwise({ redirectTo: '/view1' });
});
</script>
</body>
</html>