{"action":"created","issue":{"url":"https://api.github.com/repos/DingWentao1234/smartCampus/issues/5","repository_url":"https://api.github.com/repos/DingWentao1234/smartCampus","labels_url":"https://api.github.com/repos/DingWentao1234/smartCampus/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/DingWentao1234/smartCampus/issues/5/comments","events_url":"https://api.github.com/repos/DingWentao1234/smartCampus/issues/5/events","html_url":"https://github.com/DingWentao1234/smartCampus/issues/5","id":154615111,"number":5,"title":"恶心的success问题","user":{"login":"DingWentao1234","id":11213298,"avatar_url":"https://avatars.githubusercontent.com/u/11213298?v=3","gravatar_id":"","url":"https://api.github.com/users/DingWentao1234","html_url":"https://github.com/DingWentao1234","followers_url":"https://api.github.com/users/DingWentao1234/followers","following_url":"https://api.github.com/users/DingWentao1234/following{/other_user}","gists_url":"https://api.github.com/users/DingWentao1234/gists{/gist_id}","starred_url":"https://api.github.com/users/DingWentao1234/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DingWentao1234/subscriptions","organizations_url":"https://api.github.com/users/DingWentao1234/orgs","repos_url":"https://api.github.com/users/DingWentao1234/repos","events_url":"https://api.github.com/users/DingWentao1234/events{/privacy}","received_events_url":"https://api.github.com/users/DingWentao1234/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-13T01:25:24Z","updated_at":"2016-06-09T09:59:12Z","closed_at":null,"body":"发现angularjs中有一个很难搞定的问题\r\n\r\n我把$http写在service中，并且把promise返回，这个时候由controller操作\r\n\r\n但是当我在success函数中使用任何我注入到controller中的其他service里的方法的时候，根本不能起到任何作用。\r\n\r\n害的我好多次在success里写原生的代码，这点bug真的不知道怎么解决。自己还是不太了解angular底层的机制呢。\r\n\r\n附上一小段代码\r\n\r\n```js\r\n.success(function(data) {\r\n      // ls.setObject(\"userdata\",\"data\");\r\n      var errorinfo = \"\";\r\n      if(data.name_or_phone_error || data.password_error || data.login_error) {\r\n        errorinfo = \"用户名或密码错误\"\r\n      }\r\n      \r\n      if(data.user_status) {\r\n        // 登陆成功\r\n        window.localStorage.setItem(\"userdata\",JSON.stringify(data));\r\n        window.location.href = \"#/tab/account\";\r\n        $rootScope.isLogin = true;\r\n      }\r\n      else if(!data.user_status){\r\n        $scope.showAlert(errorinfo);\r\n      }\r\n}\r\n```\r\n\r\n其实在这里我完全可以用一个别的service来处理本地存储，而不是用原生代码来写。但是这里的bug我并不知道怎么解决。"},"comment":{"url":"https://api.github.com/repos/DingWentao1234/smartCampus/issues/comments/224851402","html_url":"https://github.com/DingWentao1234/smartCampus/issues/5#issuecomment-224851402","issue_url":"https://api.github.com/repos/DingWentao1234/smartCampus/issues/5","id":224851402,"user":{"login":"DingWentao1234","id":11213298,"avatar_url":"https://avatars.githubusercontent.com/u/11213298?v=3","gravatar_id":"","url":"https://api.github.com/users/DingWentao1234","html_url":"https://github.com/DingWentao1234","followers_url":"https://api.github.com/users/DingWentao1234/followers","following_url":"https://api.github.com/users/DingWentao1234/following{/other_user}","gists_url":"https://api.github.com/users/DingWentao1234/gists{/gist_id}","starred_url":"https://api.github.com/users/DingWentao1234/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DingWentao1234/subscriptions","organizations_url":"https://api.github.com/users/DingWentao1234/orgs","repos_url":"https://api.github.com/users/DingWentao1234/repos","events_url":"https://api.github.com/users/DingWentao1234/events{/privacy}","received_events_url":"https://api.github.com/users/DingWentao1234/received_events","type":"User","site_admin":false},"created_at":"2016-06-09T09:59:12Z","updated_at":"2016-06-09T09:59:12Z","body":"所有以上问题都是理解上的错误，我理解错了依赖注入，一直以为不仅要在开始注入，还要在使用的相关函数中再注入，结果就是造成参数被覆盖，原有注入的服务失效。\r\n\r\n所以bug fix. \r\n\r\n我在segmentfault上提问的链接 https://segmentfault.com/q/1010000005680987"}}
{"actor":{"display_login":"DingWentao1234"}}