My problem is how to transfer my Angular Directive to an JavaScript function. Ben searching for a weak now with out any success.
Since I have confidentiality agreement with my employer I can't share any of my code, but I think that question is easily understood.
Can any one give me some advice?
Here is a simple example, Ill try to be clear as a beginner can be.
This is a directive:
app.directive('helloWorld', function() {
return {
restrict: 'AE',
replace: true,
template: '<p style="background-color:{{color}}">Hello World',
link: function(scope, elem, attrs) {
elem.bind('click', function() {
elem.css('background-color', 'white');
scope.$apply(function() {
scope.color = "white";
});
});
elem.bind('mouseover', function() {
elem.css('cursor', 'pointer');
});
}
};
});
What I would like to do is something like this:
function directiveWraper(scope, elem, attrs){
app.directive('helloWorld', function() {
return {
restrict: 'AE',
replace: true,
template: '<p style="background-color:{{color}}">Hello World',
link: function(scope, elem, attrs) {
elem.bind('click', function() {
elem.css('background-color', 'white');
scope.$apply(function() {
scope.color = "white";
});
});
elem.bind('mouseover', function() {
elem.css('cursor', 'pointer');
});
}
};
});
}
So I would like to wrap a directive in a javascript function, an pull all the params in that function.