【发布时间】:2019-12-25 18:11:30
【问题描述】:
我是 Angular 的新手。我正在学习指令。我正在使用来自primeng 的pTooltip。但是我想根据条件在pTooltip中显示文本。
让我们以 Stack Overflow 本身为例。您不能两次投票赞成一个答案。如果用户没有为该特定文章投票,他应该得到 msg1,否则他应该得到 msg2。地点:
msg1="I found this article very useffeul.";
msg2="You've already upvoted this article";
这是我的代码:
article.component.html
<button
class="btn btn-success"
*ngIf="allowUpvote ? pTooltip={{msg1}} : pTooltip={{msg2}}
[disabled]="!allowUpvote">
UPVOTE
</button>
article.component.ts
...
allowUpvote=true;
msg1="I found this article very useffeul.";
msg2="You've already upvoted this article";
...
ngOnInit() {
for(var i=0;i<5;i++) {
if(this.currentLoggedInUserId==this.articleDetails.upvotersList[i]) {
this.allowUpvote=false; //It will be set false if the user is there in the upvoters list
}
}
});
但是我收到了这个错误:
解析器错误:绑定不能包含 [allowUpvote 中的第 24 列的赋值? pTooltip={{msg1}} : pTooltip={{msg2}}]
请给我一些指示。
【问题讨论】:
标签: angular typescript angular-ng-if