Changing scope variable on ng-click without calling a function

14.7k views Asked by At

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

There are 1 answers

0
Pankaj Parkar On BEST ANSWER

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>