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