我試圖創建一個指示採用了棱角分明1.5.0-β2在指令採用了棱角分明
我想使用該指令一個HTTP請求,將數據粘貼到視圖。通常它使用$ scope完成,但似乎我不能在指令中使用$ scope。
這是我到目前爲止的代碼:
app.directive('latestDrinks', ['ParseGlobalImageIdService',function (ParseGlobalImageIdService) {
return {
restrict: 'E',
templateUrl: 'views/latest-drinks.html',
controller: ['$http','$scope', function($http,$scope) {
$scope.latestDrinksRows = $http({
method: 'GET',
url: 'http://api.myalcoholist.com:8888/cocktail/get_latest_drinks'
}).then(function successCallback(response) {
response.data.forEach(function (element, index, array) {
element.global_image_id = ParseGlobalImageIdService.thumb(element.global_image_id);
})
return response.data;
}, function errorCallback(response) {
alert('error');
return null;
});
}],
}}]);
,你可以在返回的對象的控制特性看,我嘗試注入$ http和$範圍。並使用$ scope來設置latestDrinksRows
以便能夠在視圖中使用它。
說我遇到的問題是,當我嘗試打印變量視圖
{{latestDrinksRows}}
我得到一個空的對象。
我用鉻檢查器檢查和http請求正在正確發送和有效的json數據返回。
我也google了很多,我注意到沒有人真的試圖擴大$ scope在控制器屬性,所以我猜我缺少的東西。
有關該問題的任何信息將不勝感激。