我想在这里遵循基本的Angular 2教程:
https://angular.io/docs/js/latest/guide/displaying-data.html
我可以使用以下代码加载角度应用并显示我的名字:
import { Component, View, bootstrap } from 'angular2/angular2';
@Component({
selector: "my-app"
})
class AppComponent {
myName: string;
names: Array<string>;
constructor() {
this.myName = "Neil";
}
}
bootstrap(AppComponent);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试添加一个字符串数组并尝试使用ng-for显示它们时,它会抛出以下错误:
Can't bind to 'ng-forOf' since it isn't a known native property ("
<p>Friends:</p>
<ul>
<li [ERROR ->]*ng-for="#name of names">
{{ name }}
</li>
"): AppComponent@4:16
Property binding ng-forOf not used by any directive on an embedded template ("
<p>Friends:</p>
<ul>
[ERROR ->]<li *ng-for="#name of names">
{{ name }} …Run Code Online (Sandbox Code Playgroud) 我对Angular的世界很新.CommonModulevs 之间有什么区别BrowserModule?为什么一个应该优先于另一个?
将 nx 工作区升级到 v12 后,一切都像以前一样工作,IDE 中包含预期的模板。
IDE(WebStorm)显示一些以前从未发生过的奇怪错误:

第一个警告表示属性 ngIf 上没有匹配任何指令,即使导入了,第二个错误也与Missing require() 语句相关CommonModule,并且asyncvar async = require('@angular/core/testing').async;
这真的很有趣,因为构建整个 monorepo 工作完美,所以我猜这可能是由一些不正确的 linting 配置引起的。不得不说,工作区不仅更新到了最新版本,还nx进行了转换tslint。eslint
过去有人遇到过类似的问题吗?
我对 Angular 的 Karma Jasmine 测试@Component抱怨说
错误:“无法绑定到‘ngIf’,因为它不是‘p’的已知属性。”
当应用程序本身出现此类错误时,修复方法是确保将其添加BrowserModule到应用程序模块 ( )imports: []中。我确实有这个导入(所以这个问题不是关于“无法绑定到 'ngXXX' 因为它不是 'YYY' 的已知属性”的规范问题的重复)。@NgModule()app.module.ts
这是我的测试设置代码:
let component: MyComponent;
let fixture: ComponentFixture<MyComponent>;
beforeEach(async () => {
TestBed.configureTestingModule({
imports: [
BrowserModule
],
providers: [
MyComponent,
{ provide: MyService, useClass: MockMyService }
]
}).compileComponents();
TestBed.inject(MyService);
component = TestBed.inject(MyComponent);
fixture = TestBed.createComponent(MyComponent);
fixture.detectChanges();
});
Run Code Online (Sandbox Code Playgroud)
我的 HTML 模板显示*ngIf,不是ngIf或拼写错误,这是该错误消息的另一个常见原因:
<div class="self">
<p *ngIf="isLoggedIn() else selfLogin">Logged in …Run Code Online (Sandbox Code Playgroud) 模板 TR 未显示,并生成错误:NG0303:无法绑定到“ngForOf”,因为它不是“tr”的已知属性。我不明白为什么。我在 Angular 11 和 navigator Chrone
控制台 html 中出现错误:
Run Code Online (Sandbox Code Playgroud)<div> <h1 class="module-title">Job logs</h1> <span class="sp-notice">the time zone is set on GMT</span> <div class="container"> <table class="table table-striped"> <thead> <tr> <th scope="col">#JobFirst</th> <th scope="col">Last start</th> <th scope="col">Last Finish</th> <th scope="col">Time</th> </tr> </thead> <tbody> <tr *ngFor="let item of jobs"> <th>{{ item.JobName }}</th> <td>{{ item.LastStartOperation }}</td> <td>{{ item.LastFinishOperation }}</td> <td>{{ item.Time }}</td> </tr> </tbody> </table> </div> </div>
这是文件 component.ts 的内容:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-joblog',
templateUrl: './joblog.component.html', …Run Code Online (Sandbox Code Playgroud) 我需要帮助在Angular 4中显示来自api的subscribe输出.我怎么能这样做,因为我写了data.data.data,但它说属性数据不存在于类型对象上.我将如何在浏览器中输出?这是我下面的代码和下面的api图片
import { Component, OnInit } from '@angular/core';
import { NewsService } from '../news.service';
@Component({
selector: 'app-news-list',
templateUrl: './news-list.component.html',
styleUrls: ['./news-list.component.css']
})
export class NewsListComponent implements OnInit {
constructor(private newsService: NewsService) { }
ngOnInit() {
this.newsService.getNews()
.subscribe(
data => {
alert("News Success");
console.log(data);
},
error => {
alert("ERROR");
});
}
}
Run Code Online (Sandbox Code Playgroud)