这是我的两个指令。我基本上想在他们之间分享范围。然而,我得到一个未定义的$http
错误。我知道我需要放在$http
某个地方,但是在哪里呢?
aresAnalytics.directive('market', function($http) {
return {
restrict: 'E',
controller: function ($scope, Data) {
$scope.data = Data;
},
link: function(scope, element, attrs) {
element.bind('click', function() {
console.log("A1 " + attrs.market);
scope.temp = attrs.market;
$http.get('get_markets').success(function(markets) {
Data.markets = markets;
});
})
}
}
});
aresAnalytics.directive('events', function($http) {
return {
restrict: 'E',
controller: function ($scope) {
scope = $scope;
},
link: function(scope, element) {
element.bind('click', function() {
console.log(scope.temp);
});
}
}
});
HTML:
<market ng-repeat="market in data.markets" market="{{ market }}">
{{ market }}
</market>
另外,我认为我这样做的方式
$http.get('get_markets').success(function(markets) {
Data.markets = markets;
});
不正确,我可以用它代替什么。
而且,我应该改用 Isolate Scope '@' 吗?那会是什么样子?
感谢您阅读本文!