4
如何從控制器獲取一些數據並在指令中使用它,這不是問題。 但是,當我需要從指令中獲取數據並在控制器中使用它時,會出現這種情況。控制器和指令之間的AngularJS通信
對於exmpl:
我的控制器:
function MyController($scope, $location, myDirective) {
"use strict";
// here i need use scope.importantValue and create() method from directive
}
我的指令:
.directive("myDirective", function() {
"use strict";
return {
restrict: 'A',
template: '<div></div>',
replace: true,
scope: {
data: '=',
},
link: function(scope, elm) {
scope.importantValue = "value";
function create() {
console.log("Directive works...");
}
};
})
我如何使用我的控制器內從指令變量或/和方法?
你爲什麼要這麼做? – lucuma 2013-05-10 13:38:45
你不應該這樣做 – 2013-05-10 13:56:16
我們轉而指示了一些類似於少數視圖的代碼部分,這個指令包含了一些可以在項目其他部分使用的變量。我想知道是否可以在控制器中使用這些變量? – Lugaru 2013-05-10 14:03:20