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