-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseven.html
64 lines (58 loc) · 2.24 KB
/
seven.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
52
53
54
55
56
57
58
59
60
61
62
63
64
<!doctype html>
<!--
Author: Xan Gutierrez
Date: 2015-07-28
-->
<html data-ng-app="myApp">
<head>
<title>Using AngularJS Factory</title>
<meta charset="utf-8" />
</head>
<body data-ng-controller="simpleController">
<div>
<div data-ng-view=""></div>
</div>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-route/angular-route.min.js"></script>
<script>
var app = angular.module('myApp', ['ngRoute']);
app.controller('simpleController', function ($scope, simpleFactory) {
$scope.customers = [];
$scope.customers = simpleFactory.getCustomers();
$scope.addCustomer = function () {
$scope.customers.push({
name: $scope.newCustomer.name,
city: $scope.newCustomer.city
});
};
});
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'pages/view1.html',
controller: 'simpleController'
})
.when('/view2',
{
templateUrl: 'pages/view2.html',
controller: 'simpleController'
})
.otherwise({redirectTo: '/'});
});
app.factory('simpleFactory', function () {
var factory = {};
var customers = [
{name: 'John Smith', city: 'Phoenix'},
{name: 'John Doe', city: 'New York'},
{name: 'Jane Doe', city: 'San Francisco'}
];
factory.getCustomers = function (){
return customers;
};
factory.postCustomers = function (){
};
return factory;
});
</script>
</body>
</html>