在此play中,我有一个来自项目的演示。
我想在菜单中更改颜色文本。
在html中,我使用了以下代码:
<GridLayout rows="*,60">
<StackLayout row="1" orientation="horizontal" class="foot" backgroundColor="#eae8e8" padding="10 5 10 5">
<StackLayout (tap)="gofp()" width="45%" textAlignment="center">
<Label text="Home">
</Label>
</StackLayout>
<StackLayout (tap)="gosettings()" width="55%" textAlignment="center">
<Label text="Settings">
</Label>
</StackLayout>
</StackLayout>
</GridLayout>
我尝试这样的功能:
declare var $: any;
$(function () {
$("#myMenu label").click(function () {
$("#myMenu label").removeClass("active");
$(this).addClass("active");
});
});
但显示此错误:
$未定义
您能给我什么想法吗,当我选择它时如何更改颜色文本?
谢谢
答案 0 :(得分:3)
请勿使用jQuery。最简单的方法是使用ngClass。 [ngClass]="{ 'active': itemActive }
。然后(点击)标签,可以将itemActive
设置为true,然后在Label上拥有active
类。
传递事件,以便您知道单击了哪个项目并相应地添加课程。
答案 1 :(得分:1)
我本人是一个相对较新的Nativescript / Angular开发人员,但是据我所知,您不需要使用jQuery进行这样的更改(而且我不确定它是否也可以运行,但是我可以错误)。使用ViewChild
和ElementRef
,您可以访问元素的属性并直接更改它们。尝试参考并调整this playground以获得所需的效果。