0
下面是代码:
var app = angular.module('componentsApp', []);
app.directive('components', ["$http", function($http) {
return {
restrict: 'E',
templateUrl: "component.html",
controller: function() {
this.heading = "Available Data";
this.results= [];
$http.get("data.json").success(function(data) {
this.results = data;
});
},
controllerAs: 'component'
};
}]);
Components.html
<h3>{{ component.heading }}</h3>
<div ng-repeat="result in component.results">
<span>{{ result.name }}</span>
<span>{{ result.description }}</span>
</div>
当我运行它时,图标变显示为空。我想这与自$ http调用使用promises以后指令构造元素时存在的数据问题有关。
任何人都可以证实这一点吗?如果是这样,解决方案是什么?
你可以添加component.html的相关部分?另外,什么是'图标'变量? – 2014-12-08 06:46:09
如何在您的$ http中访问外部此上下文.... – Akilan 2014-12-08 07:02:52