admin管理员组文章数量:1312732
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;
}
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;
}
Share
Improve this question
edited Jun 8, 2015 at 19:35
isherwood
61.1k16 gold badges121 silver badges169 bronze badges
asked Jun 8, 2015 at 19:17
BodyBody
3,6889 gold badges43 silver badges51 bronze badges
1
-
Typo change
===
to=
@data-ng-click="pctrl.editState === 1"
todata-ng-click="pctrl.editState = 1"
. You need assignment operator (=
) not parison operator (===
). – PSL Commented Jun 8, 2015 at 19:18
1 Answer
Reset to default 5While 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>
本文标签: javascriptChanging scope variable on ngclick without calling a functionStack Overflow
版权声明:本文标题:javascript - Changing scope variable on ng-click without calling a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741907100a2404212.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论