簡體   English   中英

Angular 7 模板更改未反映在 MVC 5 中

[英]angular 7 template changes not reflecting in MVC 5

我在 Visual Studio 2019 中使用帶有 MVC5 的 angular 7。在 index.cshtml 中渲染 angular 模板時遇到問題。 我正在使用 .cshtml 訪問 index.cshtml 中的 angular 模板。 它在 index.cshtml 中加載了完美的角度模板,但是當我在 app.component.html 中進行一些更改時,這些更改並未反映在 index.cshtml 中,並且它在瀏覽器中顯示舊的默認模板。 盡管我刷新了緩存,甚至在 chrome 中禁用了緩存,但仍在加載舊的默認模板。 我無法理解為什么這個默認模板還不存在卻顯示出來。 當我更改選擇器名稱時,它不會在我的 cshtml 中顯示任何內容。 這是我的代碼

應用程序組件:

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>

捆綁配置:

          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.*"));

主文件

   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));

您的方法是錯誤的,因為您沒有使用 CLi 運行 angular 應用程序,因此如果您不為 angular 應用程序運行構建命令,您將不會看到更改

運行 ng build(如果您使用 Angular CLI)或使用您的 build 命令構建 Angular 應用程序,然后刷新瀏覽器以查看更改

在 VS Code 中打開您的項目。 使用終端中的 ng build 命令構建它。 構建成功后,在VS 2019中重新打開並運行。 這基本上編譯了您的角度文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM