为什么我无法在简单的 CRM angular Web 应用程序中显示成功消息?
Why I'm not able to display the success message in my simple CRM angular web application?
在我的 Basic Angular 应用程序中,我无法在编写正确的代码后显示成功消息。
1)app.component.html
<h1 class="c1">{{title}}</h1>
<div *ngIf="success_msg;" style="background-color:aquamarine;">
User added successfully
</div>
<router-outlet></router-outlet>
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: '<h1>{{title}}</h1>',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'Simple_CRM_App';
success_msg = true;
}
输出文件
Angular App
您应该使用 templateUrl 而不是模板
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'app';
}
问题出在 template
目前您已经在组件中添加了模板,因此无论您在 app.component.html
中添加什么都不起作用,
现在你必须要么像这样使用 templateUrl
而不是 template
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'Simple_CRM_App';
success_msg = true;
}
或者如果您只想使用模板,请像这样更新您的模板
@Component({
selector: 'my-app',
template: `
<h1 class="c1">{{title}}</h1>
<div *ngIf="success_msg" style="background-color:aquamarine;">
User added successfully
</div>
`,
styleUrls: ['./app.component.css']
})
在我的 Basic Angular 应用程序中,我无法在编写正确的代码后显示成功消息。
1)app.component.html
<h1 class="c1">{{title}}</h1>
<div *ngIf="success_msg;" style="background-color:aquamarine;">
User added successfully
</div>
<router-outlet></router-outlet>
app.component.ts
import { Component } from '@angular/core'; @Component({ selector: 'app-root', template: '<h1>{{title}}</h1>', styleUrls: ['./app.component.scss'] }) export class AppComponent { title = 'Simple_CRM_App'; success_msg = true; }
输出文件
Angular App
您应该使用 templateUrl 而不是模板
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'app';
}
问题出在 template
目前您已经在组件中添加了模板,因此无论您在 app.component.html
中添加什么都不起作用,
现在你必须要么像这样使用 templateUrl
而不是 template
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'Simple_CRM_App';
success_msg = true;
}
或者如果您只想使用模板,请像这样更新您的模板
@Component({
selector: 'my-app',
template: `
<h1 class="c1">{{title}}</h1>
<div *ngIf="success_msg" style="background-color:aquamarine;">
User added successfully
</div>
`,
styleUrls: ['./app.component.css']
})