ch04-02-simple-ng-model2.html
959 Bytes
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
<!DOCTYPE html>
<html ng-app="notesApp">
<head>
<title>Notes App</title>
<script src="../../tp/angular.js"></script>
<style>
span {
background-color: #cce;
}
</style>
</head>
<body ng-controller="MainCtrl as ctrl">
<input type="text" ng-model="ctrl.username"/>
<input type="password" ng-model="ctrl.password"/>
<button ng-click="ctrl.change()">Change values</button>
<button ng-click="ctrl.submit()">Submit</button>
<script type="text/javascript">
angular.module('notesApp', []).controller('MainCtrl', [
function () {
var self = this;
self.change = function () {
self.username = 'changed';
self.password = 'password';
};
self.submit = function () {
console.log('user clicked submit with ',
self.username, self.password);
};
}
]);
</script>
</body>
</html>