Hello, I have a ng-click ("alterardata ();") rule and the controller that calls this directive has this function by default but the problem is that I click on the button and it does not work I put another button on the main page and it works
Hello, I have a ng-click ("alterardata ();") rule and the controller that calls this directive has this function by default but the problem is that I click on the button and it does not work I put another button on the main page and it works
Use a callback .
In your directive, set a scope property that will receive controller callback :
app.directive('exemploDiretiva', function () {
return {
restrict: 'AE',
template: '<h3>Olá!</h3>',
scope: {
chamadaCallback: '&' // <- Define uma referência de função externa
},
link: function (scope, element, attrs) {
}
};
});
This is done by setting the value in view :
<exemplo-diretiva chamada-callback="meuMetodoDoController(arg1)"></exemplo-diretiva>
Note that while the definition is in the
camelCase
(chamadaCallback
) format, the parameterization must be done inlowercase-dash
(chamada-callback
) format.
With this done, create the meuMetodoDoController
method in controller - it will be invoked when, in policy, you invoke the callback as follows:
scope.chamadaCallback('qualquerParametroQueVoceQuiser');