Angular 角度6*Ng,用于指令不工作
在将cli升级到v6之后,我刚刚创建了一个新项目,并使用Angular Material util添加了仪表板布局 我只是在胡闹,意识到ngFor不适合我 我确保CommonModule正在导入,我检查其他指令是否像Angular 角度6*Ng,用于指令不工作,angular,angular-directive,Angular,Angular Directive,在将cli升级到v6之后,我刚刚创建了一个新项目,并使用Angular Material util添加了仪表板布局 我只是在胡闹,意识到ngFor不适合我 我确保CommonModule正在导入,我检查其他指令是否像*ngIf那样工作。我是做错了什么,还是更新后有些东西坏了 测试组件: import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-test', templateUrl: '.
*ngIf
那样工作。我是做错了什么,还是更新后有些东西坏了
测试组件:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
topics: ['C','C#']
constructor() { }
ngOnInit() {
}
}
Html:
话题
- {{topic}
我刚刚将我的应用程序测试组件放在仪表板快速启动构建的卡中,下面是呈现的内容
截图:
Ng--版本:
您正在声明主题的类型,而不是初始化它 试一试 测试组件
您被声明为变量,但没有初始化它。试试这个
export class TestComponent implements OnInit {
topics: [] = ['C','C#']
constructor() { }
ngOnInit() {
}
}
说明:
主题:['C','C#']
在这段代码中,typescript是如何处理它的['C','C#']
是主题
变量的数据类型,而不是为该变量赋值。所以你应该像这样提供数据
主题:[]=['C','C#']
您对该li有任何css吗?或者没有css?没有css它创建了css文件,但我没有应用任何东西到你的控制台输出的东西?像一个错误我的意思是..不,这是令人困惑的部分chrome调试器中没有错误。主题:['C','C#']
->:
应该是=
嗯,现在是4:36,我意识到这是一个多么愚蠢的错误,因为我睡了一半。谢谢你抓到这个,没错。请注意,您应该使用=
来赋值,而不是:
@deezg是的,我看到我显然是半睡半醒,谢谢您的发现。@deezg更新。
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
topics: string[]
constructor() {
this.topics=['C','C#'];
}
ngOnInit() {}
}
export class TestComponent implements OnInit {
topics: [] = ['C','C#']
constructor() { }
ngOnInit() {
}
}