嗨,伙计们,我正在关注MEAN堆栈的Max的Udemy教程,我遇到了Material问题,现在元素没有显示出来。
材料和* ngFor曾经在我使计算机进入睡眠状态之前工作。 我的设置:Ubuntu,VSCode,节点:10.15.3,npm:6.7.0
这是我的repo
angular-cli也向我显示此警告:
您的全局Angular CLI版本(7.3.6)大于本地版本 版本(7.0.7)。使用本地Angular CLI版本。
<mat-accordion>
<mat-expansion-panel *ngFor="let post of posts">
<mat-expansion-panel-header>
{{post.title}}
</mat-expansion-panel-header>
<p>{{post.content}}</p>
</mat-expansion-panel>
</mat-accordion>
package.json
{
"name": "mean-course",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.0.0",
"@angular/cdk": "~7.3.5",
"@angular/common": "~7.0.0",
"@angular/compiler": "~7.0.0",
"@angular/core": "~7.0.0",
"@angular/forms": "~7.0.0",
"@angular/http": "~7.0.0",
"@angular/material": "^7.3.5",
"@angular/platform-browser": "~7.0.0",
"@angular/platform-browser-dynamic": "~7.0.0",
"@angular/router": "~7.0.0",
"core-js": "^2.5.4",
"rxjs": "~6.3.3",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.10.0",
"@angular/cli": "~7.0.3",
"@angular/compiler-cli": "~7.0.0",
"@angular/language-service": "~7.0.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.1.1"
}
}
答案 0 :(得分:1)
将post-list.component.html
的第n°9行更改为
<p class="info-text mat-body-1" ngIf="posts.length <= 0"> No posts yet!</p>
到
<p class="info-text mat-body-1" *ngIf="posts.length <= 0"> No posts yet!</p>
您错过了*
中的*ngIf
。
为警告起见,它只是说您在全局(npm install -g
)上安装的@ angular / cli比您的package.json中的一个更大,但这不是问题的根源。