{"action":"created","issue":{"url":"https://api.github.com/repos/wuchaoliang/learn-angular/issues/1","repository_url":"https://api.github.com/repos/wuchaoliang/learn-angular","labels_url":"https://api.github.com/repos/wuchaoliang/learn-angular/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/wuchaoliang/learn-angular/issues/1/comments","events_url":"https://api.github.com/repos/wuchaoliang/learn-angular/issues/1/events","html_url":"https://github.com/wuchaoliang/learn-angular/issues/1","id":170830975,"number":1,"title":"angular","user":{"login":"wuchaoliang","id":16839608,"avatar_url":"https://avatars.githubusercontent.com/u/16839608?v=3","gravatar_id":"","url":"https://api.github.com/users/wuchaoliang","html_url":"https://github.com/wuchaoliang","followers_url":"https://api.github.com/users/wuchaoliang/followers","following_url":"https://api.github.com/users/wuchaoliang/following{/other_user}","gists_url":"https://api.github.com/users/wuchaoliang/gists{/gist_id}","starred_url":"https://api.github.com/users/wuchaoliang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wuchaoliang/subscriptions","organizations_url":"https://api.github.com/users/wuchaoliang/orgs","repos_url":"https://api.github.com/users/wuchaoliang/repos","events_url":"https://api.github.com/users/wuchaoliang/events{/privacy}","received_events_url":"https://api.github.com/users/wuchaoliang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-12T09:18:19Z","updated_at":"2016-09-08T07:26:43Z","closed_at":null,"body":"## angular中$timeout和setTimeout的区别\r\n**angular中setTimeout不会刷新页面，所以‘hello’不会变成‘hi’，要用$timeout代替setTimeout**\r\n```js\r\n<!DOCTYPE html>\r\n<html ng-app=\"app\">\r\n\t<head>\r\n\t\t<meta charset=\"UTF-8\">\r\n\t\t<title></title>\r\n\t</head>\r\n\t<script src=\"angular.min.js\"></script>\r\n\t<body>\r\n\t\t<h1 ng-controller=\"ctr1\">\r\n\t\t\t{{say}}\r\n\t\t</h1>\r\n\t</body>\r\n\t<script>\r\n\t\tvar app = angular.module('app',[]);\r\n\t\tapp.controller('ctr1',['$scope','$timeout',function($scope,$timeout){\r\n\t\t\t\r\n//\t\t\t$scope.say = 'hello';\r\n//\t\t\tsetTimeout(function(){\r\n//\t\t\t\t$scope.say = 'hi';\r\n//\t\t\t},2000)\r\n\t\t\t$timeout(function(){\r\n\t\t\t\t$scope.say = 'hi';\r\n\t\t\t},2000)\r\n\t\t}])\r\n\t</script>\r\n</html>\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/wuchaoliang/learn-angular/issues/comments/245515695","html_url":"https://github.com/wuchaoliang/learn-angular/issues/1#issuecomment-245515695","issue_url":"https://api.github.com/repos/wuchaoliang/learn-angular/issues/1","id":245515695,"user":{"login":"wuchaoliang","id":16839608,"avatar_url":"https://avatars.githubusercontent.com/u/16839608?v=3","gravatar_id":"","url":"https://api.github.com/users/wuchaoliang","html_url":"https://github.com/wuchaoliang","followers_url":"https://api.github.com/users/wuchaoliang/followers","following_url":"https://api.github.com/users/wuchaoliang/following{/other_user}","gists_url":"https://api.github.com/users/wuchaoliang/gists{/gist_id}","starred_url":"https://api.github.com/users/wuchaoliang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wuchaoliang/subscriptions","organizations_url":"https://api.github.com/users/wuchaoliang/orgs","repos_url":"https://api.github.com/users/wuchaoliang/repos","events_url":"https://api.github.com/users/wuchaoliang/events{/privacy}","received_events_url":"https://api.github.com/users/wuchaoliang/received_events","type":"User","site_admin":false},"created_at":"2016-09-08T07:26:42Z","updated_at":"2016-09-08T07:26:42Z","body":"## 触摸滑动指令（上左下右四个方向）\r\n```js\r\n<!DOCTYPE html>\r\n<html ng-app=\"app\">\r\n\r\n\t<head>\r\n\t\t<meta charset=\"UTF-8\">\r\n\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1\">\r\n\t\t<title></title>\r\n\t</head>\r\n\r\n\t<body ng-controller=\"indexCtrl\">\r\n\t\t<p id=\"touch\" ng-touch=\"touch()\">{{name}}</p>\r\n\t</body>\r\n\t<script src=\"js/angular.js\"></script>\r\n\t<script>\r\n\t\tvar app = angular.module('app', []);\r\n\t\tapp.controller(\"indexCtrl\", function($scope) {\r\n\t\t\t$scope.name = \"124\"\r\n\t\t\t$scope.touch = function(){\r\n\t\t\t\tconsole.log(\"触发了滑动事件\")\r\n\t\t\t}\r\n\t\t\t\t/*var xStart, xEnd, yStart, yEnd;\r\n\t\t\t\tdocument.getElementsByTagName(\"body\")[0].addEventListener('touchstart', function(e) {\r\n\t\t\t\t\t//console.log(\"触摸开始的坐标\" + e.targetTouches[0].pageX + e.targetTouches[0].pageY)\r\n\t\t\t\t\t//触摸开始的X坐标和Y坐标\r\n\t\t\t\t\txStart = e.targetTouches[0].pageX;\r\n\t\t\t\t\tyStart = e.targetTouches[0].pageY;\r\n\t\t\t\t})\r\n\t\t\t\tdocument.getElementsByTagName(\"body\")[0].addEventListener('touchmove', function(e) {\r\n\t\t\t\t\t//console.log(\"触摸时    的坐标\" + e.targetTouches[0].pageX + e.targetTouches[0].pageY)\r\n\t\t\t\t})\r\n\t\t\t\tdocument.getElementsByTagName(\"body\")[0].addEventListener('touchend', function(e) {\r\n\t\t\t\t\t//console.log(\"触摸结束时的坐标\" + e.changedTouches[0].pageX + e.changedTouches[0].pageY)\r\n\t\t\t\t\txEnd = e.changedTouches[0].pageX;\r\n\t\t\t\t\tyEnd = e.changedTouches[0].pageY;\r\n\t\t\t\t\tdirection(xStart, xEnd, yStart, yEnd)\r\n\t\t\t\t})\r\n\r\n\t\t\t\tfunction direction(xStart, xEnd, yStart, yEnd) {\r\n\t\t\t\t\tconsole.log(\"xStart:\" + xStart + \"xEnd:\" + xEnd + \"yStart:\" + yStart + \"yEnd:\" + yEnd);\r\n\t\t\t\t\tif(Math.abs(xStart - xEnd) >= Math.abs(yStart - yEnd)) {\r\n\t\t\t\t\t\tif(xStart >= xEnd) {\r\n\t\t\t\t\t\t\tconsole.log(\"left\")\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tconsole.log(\"right\")\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tif(yStart >= yEnd) {\r\n\t\t\t\t\t\t\tconsole.log(\"up\")\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tconsole.log(\"down\")\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}*/\r\n\t\t})\r\n\t\tapp.directive('ngTouch', function() {\r\n\t\t\treturn {\r\n\t\t\t\tlink: function(scope, ele, attr) {\r\n\t\t\t\t\tvar xStart, xEnd, yStart, yEnd;\r\n\t\t\t\t\tfunction direction(xStart, xEnd, yStart, yEnd) {\r\n\t\t\t\t\t\tconsole.log(\"xStart:\" + xStart + \"xEnd:\" + xEnd + \"yStart:\" + yStart + \"yEnd:\" + yEnd);\r\n\t\t\t\t\t\tif(Math.abs(xStart - xEnd) >= Math.abs(yStart - yEnd)) {\r\n\t\t\t\t\t\t\tif(xStart >= xEnd) {\r\n\t\t\t\t\t\t\t\tconsole.log(\"left\")\r\n\t\t\t\t\t\t\t\tscope.$apply(scope.touch())\r\n\t\t\t\t\t\t\t\talert(\"left\")\r\n\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\tconsole.log(\"right\")\r\n\t\t\t\t\t\t\t\tscope.$apply(scope.touch())\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\tif(yStart >= yEnd) {\r\n\t\t\t\t\t\t\t\tconsole.log(\"up\")\r\n\t\t\t\t\t\t\t\tscope.$apply(scope.touch())\r\n\t\t\t\t\t\t\t} else {\r\n\t\t\t\t\t\t\t\tconsole.log(\"down\")\r\n\t\t\t\t\t\t\t\tscope.$apply(scope.touch())\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tele.bind('touchstart', function(e) {\r\n\t\t\t\t\t\txStart = e.targetTouches[0].pageX;\r\n\t\t\t\t\t\tyStart = e.targetTouches[0].pageY;\r\n\t\t\t\t\t})\r\n\t\t\t\t\tele.bind('touchend', function(e) {\r\n\t\t\t\t\t\txEnd = e.changedTouches[0].pageX;\r\n\t\t\t\t\t\tyEnd = e.changedTouches[0].pageY;\r\n\t\t\t\t\t\tdirection(xStart, xEnd, yStart, yEnd)\r\n\t\t\t\t\t})\r\n\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t})\r\n\t</script>\r\n\r\n</html>\r\n```\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"wuchaoliang"}}