Angularjs 调用从另一个控制器写入指令内的函数
我有一个指示如下:Angularjs 调用从另一个控制器写入指令内的函数,angularjs,angularjs-directive,angularjs-controller,Angularjs,Angularjs Directive,Angularjs Controller,我有一个指示如下: angular.module('test.directives').directive("resize", function($window) { return function(scope, element) { var w; w = angular.element($window); scope.getWindowDimensions = function() { return {
angular.module('test.directives').directive("resize", function($window) {
return function(scope, element) {
var w;
w = angular.element($window);
scope.getWindowDimensions = function() {
return {
h: w.height(),
w: w.width()
};
};
};
});
如何从其他控制器调用scope.getWindowDimensions?可能吗
请帮忙,
谢谢。是的,你不应该这样做,但如果你想要,你可以这样做 如本例所示:-
You need to use two way binding by
scope: {
control: '='//use for two way binding
}
你真的不应该那样做。控制器不应该调用特定指令的函数。如果两者都需要一个公共函数,您可能希望将该函数包含在服务中,并将其注入控制器和指令。