{"id":3261,"date":"2016-03-31T08:57:36","date_gmt":"2016-03-31T00:57:36","guid":{"rendered":"http:\/\/leybreeze.com\/blog\/?p=3261"},"modified":"2016-03-31T09:58:59","modified_gmt":"2016-03-31T01:58:59","slug":"%e5%86%99%e7%bb%99%e7%a8%8b%e5%ba%8f%e5%91%98%e7%9a%84-angularjs-%e8%af%ad%e6%b3%95%e5%bf%ab%e9%80%9f%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"http:\/\/leybreeze.com\/blog\/?p=3261","title":{"rendered":"\u5199\u7ed9\u7a0b\u5e8f\u5458\u7684 AngularJS \u8bed\u6cd5\u5feb\u901f\u5165\u95e8"},"content":{"rendered":"<h3>\u57fa\u672c\u793a\u4f8b<\/h3>\n<p>index.html<\/p>\n<pre class=\"lang:default decode:true\">&lt;!-- \u672c\u6bb5\u793a\u4f8b\u4ee3\u7801\u6765\u81ea AngularJS \u5b98\u65b9\u7ad9\u70b9 angularjs.org --&gt;\r\n&lt;!doctype html&gt;\r\n&lt;!-- ng-app \u8868\u793a\u5728\u5f53\u524d\u533a\u57df\u5185\u542f\u7528 AngularJS --&gt;\r\n&lt;html ng-app&gt;\r\n  &lt;head&gt;\r\n    &lt;!-- \u8f7d\u5165 AngularJS \u6587\u4ef6 --&gt;\r\n    &lt;script src=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/angularjs\/1.5.3\/angular.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;div&gt;\r\n      &lt;label&gt;Name:&lt;\/label&gt;\r\n      &lt;!-- ng-model \u8868\u793a\u5f53\u524d\u63a7\u4ef6\u4e0e\u6307\u5b9a model \u5173\u8054\u3002\u63a7\u4ef6\u53d8\u66f4\u65f6\uff0cmodel \u4e5f\u4f1a\u6539\u53d8\uff0c\u53cd\u4e4b\u4ea6\u7136 --&gt;\r\n      &lt;input type=\"text\" ng-model=\"yourName\" placeholder=\"Enter a name here\"&gt;\r\n      &lt;hr&gt;\r\n      &lt;!-- {{ }} \u7528\u4e8e\u7ed1\u5b9a model\u3002\u5f53 model \u7684\u503c\u6539\u53d8\uff0c\u6b64\u5904\u7684\u663e\u793a\u4e5f\u4f1a\u6539\u53d8  --&gt;\r\n      &lt;h1&gt;Hello {{yourName}}!&lt;\/h1&gt;\r\n    &lt;\/div&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h3>\u4f7f\u7528\u63a7\u4ef6<\/h3>\n<p>index.html<\/p>\n<pre class=\"lang:default decode:true \">&lt;!doctype html&gt;\r\n&lt;html ng-app=\"todoApp\"&gt;\r\n  &lt;head&gt;\r\n    &lt;script src=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/angularjs\/1.5.3\/angular.min.js\"&gt;&lt;\/script&gt;\r\n    &lt;!-- \u4e1a\u52a1\u903b\u8f91\u4f9d\u7136\u901a\u8fc7 JavaScript \u5b9e\u73b0 --&gt;\r\n    &lt;script src=\"todo.js\"&gt;&lt;\/script&gt;\r\n    &lt;link rel=\"stylesheet\" href=\"todo.css\"&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;h2&gt;Todo&lt;\/h2&gt;\r\n    &lt;!-- \u8be5 div \u7684\u884c\u4e3a\u5c06\u901a\u8fc7 TodoListController \u7c7b\u63a7\u5236 --&gt;\r\n    &lt;div ng-controller=\"TodoListController as todoList\"&gt;\r\n      &lt;span&gt;{{todoList.remaining()}} of {{todoList.todos.length}} remaining&lt;\/span&gt;\r\n      &lt;!-- ng-click \u5b9a\u4e49\u4e86\u70b9\u51fb\u65f6\u5c06\u8c03\u7528\u54ea\u4e2a\u65b9\u6cd5 --&gt;\r\n      [ &lt;a href=\"\" ng-click=\"todoList.archive()\"&gt;archive&lt;\/a&gt; ]\r\n      &lt;ul class=\"unstyled\"&gt;\r\n        &lt;!-- ng-repeat \u53ef\u81ea\u52a8\u904d\u5386\u5e76\u5411 DOM \u6dfb\u52a0\u5143\u7d20 --&gt;\r\n        &lt;li ng-repeat=\"todo in todoList.todos\"&gt;\r\n          &lt;label class=\"checkbox\"&gt;\r\n            &lt;input type=\"checkbox\" ng-model=\"todo.done\"&gt;\r\n            &lt;span class=\"done-{{todo.done}}\"&gt;{{todo.text}}&lt;\/span&gt;\r\n          &lt;\/label&gt;\r\n        &lt;\/li&gt;\r\n      &lt;\/ul&gt;\r\n      &lt;!-- \u70b9\u51fb\u6309\u94ae\u65f6\u5c06\u8c03\u7528 addTodo() --&gt;\r\n      &lt;form ng-submit=\"todoList.addTodo()\"&gt;\r\n        &lt;input type=\"text\" ng-model=\"todoList.todoText\"  size=\"30\"\r\n               placeholder=\"add new todo here\"&gt;\r\n        &lt;input class=\"btn-primary\" type=\"submit\" value=\"add\"&gt;\r\n      &lt;\/form&gt;\r\n    &lt;\/div&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>todo.js<\/p>\n<pre class=\"lang:js decode:true \">angular.module('todoApp', [])\r\n  .controller('TodoListController', function() {\r\n    var todoList = this;\r\n    \/\/ \u9ed8\u8ba4\u6dfb\u52a0\u4e24\u6761\u6761\u76ee\r\n    todoList.todos = [\r\n      {text:'learn angular', done:true},\r\n      {text:'build an angular app', done:false}];\r\n \r\n    todoList.addTodo = function() {\r\n      \/\/ \u501f\u52a9 Array.push() \u63d2\u5165\u6761\u76ee\r\n      todoList.todos.push({text:todoList.todoText, done:false});\r\n      todoList.todoText = '';\r\n    };\r\n \r\n    todoList.remaining = function() {\r\n      var count = 0;\r\n      angular.forEach(todoList.todos, function(todo) {\r\n        count += todo.done ? 0 : 1;\r\n      });\r\n      return count;\r\n    };\r\n \r\n    todoList.archive = function() {\r\n      var oldTodos = todoList.todos;\r\n      todoList.todos = [];\r\n      angular.forEach(oldTodos, function(todo) {\r\n        if (!todo.done) todoList.todos.push(todo);\r\n      });\r\n    };\r\n  });<\/pre>\n<p>todo.css<\/p>\n<pre class=\"lang:css decode:true \">.done-true {\r\n  text-decoration: line-through;\r\n  color: grey;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>\u672a\u5b8c\u5f85\u7eed<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u793a\u4f8b index.html &lt;!&#8211; \u672c\u6bb5\u793a\u4f8b\u4ee3\u7801\u6765\u81ea AngularJS \u5b98\u65b9\u7ad9\u70b9 angular &hellip; <a href=\"http:\/\/leybreeze.com\/blog\/?p=3261\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u5199\u7ed9\u7a0b\u5e8f\u5458\u7684 AngularJS \u8bed\u6cd5\u5feb\u901f\u5165\u95e8\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[145],"tags":[151,146],"_links":{"self":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3261"}],"collection":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3261"}],"version-history":[{"count":4,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3261\/revisions"}],"predecessor-version":[{"id":3266,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3261\/revisions\/3266"}],"wp:attachment":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3261"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}