1

How can I change a Scope Variable without calling a function from controller.

I'm trying to show a div content when the editState variable equals to 1 but it's not working.

HTML

<body data-ng-controller="profileCtrl as pctrl">

    <div data-ng-click="pctrl.editState === 1">Edit</div>

    <div data-ng-if="pctrl.editState === 1">
        .....
    </div>

</body>

JS(in profileCtrl controller)

this.editState = 0;

But when I called a function it's working (I don't want to do this way)

<div data-ng-click="pctrl.editFn()">Edit</div>

this.editFn = function() {
     this.editState = 1;
}
1
  • Typo change === to = @ data-ng-click="pctrl.editState === 1" to data-ng-click="pctrl.editState = 1". You need assignment operator (=) not comparison operator (===). Commented Jun 8, 2015 at 19:18

1 Answer 1

5

While setting value inside ng-click directive, use assignment operator = instead of === exact check operator.

It should be

<div data-ng-click="pctrl.editState = 1">Edit</div>

Instead of

<div data-ng-click="pctrl.editState === 1">Edit</div>
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.