I have on my website a code similar to the following:
<div ng-click=someFunction() my-directive>...</div>
<div ng-show=showMe>...</div>
The function someFunction() looks as follows:
function onSuccess() {
// do something
console.log("in response")
}
function someFunction() {
$http(
{
...
}).then(onSuccess);
}
The directive my-directive is created as follows:
app.directive(myDirective, function() {
return {
restrict: 'A',
link: function(scope, $elm) {
$elm.on('click', function() {
console.log("in directive");
//do something
});
}
}
});
The problem is that I need the directive to fire only after onSuccess had finished what it loaded and not before (i.e., I want to see in the console "in response" before "in directive" and right now I see "in directive" first)
It looks like something doable but I can't find how... Any help/ideas will be appreciated!
EDIT: I just saw this answer: Wait for data in controller before link function is run in AngularJS directive It is not what I'm looking for as the function someFunction is independent of the directive and I want it to stay as independent as possible (the function is placed in the controller of the app and I don't want to manipulate the view directly from there).
EDIT 2: I am aware of the possibility to use timeout but I'd rather use a more general solution. With timeout I'll have to guess how long to wait and I don't want to rely on that.
EDIT 3: I edited the function someFunction to a more specific one. I can't change the structure of someFunction and I don't want to do the directive's work in onSuccess.
thanks again!
ng-ifand not an attribute of an element.