大家。我是AngularJS的新手,发现它很有趣,但我对以下情况有点不清楚。得到范围在指令
app.controller("myCtrl", ['$scope', '$http', '$filter', function ($scope, http, filter)
{
$http({
method: CTHocUri,
url: 'get',
async: true,
}).then(function (response) {
$scope.CTH = response.data; //response.data=two Object
})
}])
app.directive("myCustom1",['$http', function ($compile,$http) {
return {
link: function (scope, element, attr) {
console.log(scope.CTH); // I can't get... scope.CTH=undefined
}
}])
我无法获得价值scope.CTH。 ??
给scope.CTH一个控制器的初始值,然后你会在指令的console.log中看到它。你现在看不到它的原因是它正在$ http成功函数中初始化,这是异步 –
是的,如何得到它 – john
@NitsanBaleli我不希望范围在指令和控制器之间共享。 – JeffryHouser