Recently, I created a directive called mySave
, and it looks like this:
app.directive('mySave', function($http) {
return function(scope, element, attrs) {
element.bind("click", function() {
$http.post('/save', scope.data).success(returnedData) {
// callback defined on my utils service here
// user defined callback here, from my-save-callback perhaps?
}
});
}
});
Here is how the element using this directive looks:
<button my-save my-save-callback="callbackFunctionInController()">save</button>
The current implementation of the callbackFunctionInController
in the controller is pretty basic:
$scope.callbackFunctionInController = function() {
alert("callback");
}
However, when I try to console.log()
attrs.mySaveCallback
within the my-save directive, it returns a string value of callbackFunctionInController()
. After reading some information suggesting that I should use $parse on this, I attempted to do so by calling $parse(attrs.mySaveCallback)
. This resulted in receiving a different function than expected:
function (a,b){return m(a,b)}
I'm unsure of what I'm doing wrong in this process. Is this approach possibly flawed from the beginning?