【发布时间】:2021-04-12 23:08:46
【问题描述】:
我在 Visual Studio 2019 中使用 Angular 7 和 MVC5。我在 index.cshtml 中渲染 Angular 模板时遇到问题。 我正在使用 .cshtml 访问 index.cshtml 中的角度模板。 它在 index.cshtml 中加载完美的角度模板,但是当我在 app.component.html 中进行一些更改时,这些更改并未反映在 index.cshtml 中,并且它在浏览器中显示旧的默认模板。尽管我刷新了缓存,甚至禁用了 chrome 中的缓存,但仍在加载旧的默认模板。我无法理解为什么这个默认模板会显示,即使它还不存在。当我更改选择器名称时,它不会在我的 cshtml 中显示任何内容。 这是我的代码
app.component:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'] })
export class AppComponent {
title = 'App';
}
index.cshtml:
@{
ViewBag.Title = "Index";
}
<app-root></app-root>
bundle.config:
bundles.Add(new ScriptBundle("~/Script/Bundles")
.Include(
"~/bundles/inline.*",
"~/bundles/runtime.*",
"~/bundles/zone.*",
"~/bundles/polyfills.*",
"~/bundles/scripts.*",
"~/bundles/vendor.*",
"~/bundles/main.*"));
bundles.Add(new StyleBundle("~/Content/Styles")
.Include("~/bundles/styles.*"));
main.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-
dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
【问题讨论】:
标签: c# asp.net-mvc angular angular7