1
我不明白为什么这段代码可以很好的与angularjs 1.2.0-rc.2配合使用,但不适用于后续版本(我试过1.2.0,1.4.9,1.5.7)角度版本和承诺的问题
的index.html
<body ng-app="MyApp">
<h1>Open Pull Requests for Angular JS</h1>
<ul ng-controller="DashboardCtrl">
<li ng-repeat="pullRequest in pullRequests">
{{ pullRequest.title }}
</li>
</ul>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script>
<!--<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js"></script>-->
<!--<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>-->
<!--<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>-->
<script src="scripts/app.js"></script>
</body>
脚本/ app.js
'use strict';
var app = angular.module('MyApp', []);
app.controller('DashboardCtrl', ['$scope', 'GithubService',function($scope, GithubService) {
$scope.pullRequests = GithubService.getPullRequests();
}]);
app.factory('GithubFactory', ['$q', '$http',function($q, $http) {
var myFactory = {};
myFactory.getPullRequests = function() {
var deferred = $q.defer();
$http.get('https://api.github.com/repos/angular/angular.js/pulls')
.success(function(data) {
deferred.resolve(data); // Success
})
.error(function(reason) {
deferred.reject(reason); // Error
});
return deferred.promise;
}
return myFactory;
}]);
调试,我可以看到的是,许是重解决,但数据不显示... 什么是正确的方式来使用承诺?
是的! Promise自动解包已自1.2.0-rc.3弃用,请参阅https://docs.angularjs.org/guide/migration#angular-expression-parsing-parse-interpolate- – electblake