【发布时间】:2018-08-28 12:14:32
【问题描述】:
我想从Directive调用Controller的一个函数,它是为了验证。但是当我使用隔离范围时,我对如何从指令中调用它有点困惑。这是指令的代码:-
App.directive('test',function(){
return{
require: "ngModel",
scope:{
a:"=",
b:"=",
c:'=',
d:'='
},
link: function(scope, element, attributes,modelVal )
{
modelVal.$validators.test= function(val)
{
return false;
//isolated scope values will make if condition true or false.
if(scope.a=="true"){
//I need to call a function of controller here. But how can
//i call that function from directive? this is my problem
}
}
scope.$watch("a", function()
{
modelVal.$validate();
});
}//end of link function;
}//end of return;
});//end of directive;
Function 在我的controller 中,我想我不需要写controller code。在我的 html 中,我将此指令称为:
<test a="1" b="2" c="3" d="4" ng-model="abc"></test>
我需要在我的directive 中进行哪些更改才能调用controller function,即$scope.testFunction()?
【问题讨论】:
标签: angularjs angularjs-scope angular-directive isolated-scope