I have a condition, in my Angular app, in the view which disables the click event if false is returned, like so:
<li data-ng-click="!$ctrl.question.q1 || activeTab = 1" data-ng-disabled="!$ctrl.question.q1">Q.1</li>
<li data-ng-click="!$ctrl.question.q2 || activeTab = 2" data-ng-disabled="!$ctrl.question.q2">Q.2</li>
If question.q2
returns false, don't change the value of activeTab
and remain disabled. The function works, however an error displays in the console:
Trying to assign a value to a non l-value
I found this thread,这解释了我如何分配值而不是比较它,但我需要分配它更改单独面板中显示的内容。在添加条件之前,选项卡功能正常工作。
问题
如何解决此错误?
<uib-tabset active="activeTab">
<uib-tab heading="" index="1" data-ng-hide="true">
//content
</uib-tab>
<uib-tab heading="" index="2" data-ng-hide="true">
//content
</uib-tab>
</uib-tabset>
答案 0 :(得分:1)
data-ng-click
内的逻辑读作&#34; NOT $ ctrl.question.q2或指定activeTab值2&#34;
我认为你想要的是一个简写if语句,使用三元运算符:
data-ng-click="activeTab = $ctrl.question.q2 ? 2 : activeTab"
其中读取为:&#34;如果$ ctrl.question.q2为true,则将值2分配给activeTab,或者如果$ ctrl.question.q2为false,则为其分配旧值&#34;