angular数据绑定---js全局学习

 1 <!DOCTYPE html>
 2 <html ng-app>
 3 <head>
 4     <title>Simple app</title>
 5 </head>
 6 <body>
 7     <div ng-controller = "MyController">
 8         <input type="text" ng-model = "name" placeholder="Your name">
 9         <h1>Hello {{name}} </h1>333
10         <h5>{{clock.now}}</h5>
11     </div>
12 <script type="text/javascript" src = "js/angular.js"></script>
13 <script type="text/javascript" src = "js/app.js">
14 </script>
15 </body>
16 </html>
View Code

下面是js里实现的全局的controller代码

 1 function MyController($scope) {
 2     $scope.clock = {
 3         now: new Date()
 4     };
 5     var updateClock = function() {
 6         $scope.clock.now = new Date()
 7     };
 8     setInterval(function() {
 9         $scope.$apply(updateClock);
10     }, 1000);
11     updateClock();
12 }
View Code

 

posted on 2017-05-22 14:52  二十年后20  阅读(125)  评论(0编辑  收藏  举报

导航