1

First of all, I'm sorry to ask simple like below.

I have no code to show you.

Maybe this seems like a kind of rude question, but I expect somebody will give me some examples.

I've succeeded to link directive and controller.

I built modal like this link.

Add element dynamically by using Modal

In my original code, modal have a button to close itself.

What I want is when I click this button, all variables related with directive to be initialized.

But I don't know how.

Help me please. Thanks in advance for any help.

4
  • Why don't you use a service?? Just broadcast and catch the event in directive and reset your variable. Commented Sep 26, 2017 at 6:52
  • @anu Well, okay. I'll consider your suggestion. But I want ways more simple or easy. thanks to your comments. :) Commented Sep 26, 2017 at 7:04
  • Is this ng2? or the old one?. Use $scope.$broadcast('eventsomethingreset') then catch it on your directive $scope.$on('eventsomethingreset', func () { //reset stuff })' if ng1 else if ng2 use RxJS Observable Commented Sep 26, 2017 at 7:10
  • @masterpreenz the old one what I'm using. I'll try this. Thanks! Commented Sep 26, 2017 at 7:24

1 Answer 1

2

ng-if will re-render the element to which it is applied

For Example

In html

<my-directive ng-if="reRender"></my-directive>

<button ng-click="resetDirective();">Reset Directive</button>

In Controller

$scope.reRender = true; //initial value

$scope.resetDirective = function(){
    $scope.reRender = false;
    var timer = $timeout(function(){
        $scope.reRender = true;
        $timeout.cancel(timer);
    }, 500);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.