【问题标题】:Setup angular 2/4 with MVC 5 in visual studio 2015在 Visual Studio 2015 中使用 MVC 5 设置角度 2/4
【发布时间】:2017-06-09 18:08:46
【问题描述】:

我正在尝试将 angular-cli 生成的 Angular 4 与 MVC 5 集成。我需要通过 MVC 视图加载 Angular。有人可以告诉我该怎么做。大多数示例显示在布局文件中引用 systemjs.js。 Angular cli 不会生成该文件,而是使用 .angular-cli.json 文件。我还需要加载 index.cshtml 而不是 index.html

.angular-cli.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "MRDB.Web"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.css"
      ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json"
    },
    {
      "project": "src/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

索引.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Angular4app</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
  <app-root>Loading...</app-root>
</body>
</html>

启动

using Microsoft.Owin;
using Owin;

[assembly: OwinStartupAttribute(typeof(MRDB.Startup))]
namespace MRDB
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}

【问题讨论】:

  • 有一个教程heregithub上有源代码
  • 嗨,詹姆斯,我确实看到了。我的问题是,我使用不包含 systemjs 的 angular cli 生成。该示例使用 systemjs 来配置应用程序。我正在考虑将 angularcli 生成的源代码与 MVC5 集成

标签: asp.net-mvc angular angular-cli


【解决方案1】:

我不知道怎么做,但你真的想这样做吗?据我了解,Angular 是一个完整的前端框架,你可以简单地将所有文件放到一个站点而不是一个 MVC 项目。

【讨论】:

  • 嗨,Simon,我同意 Angular 是一个完整的框架,但也有一些项目采用混合方法来利用 MVC 和 razor 的优势。
猜你喜欢
  • 1970-01-01
  • 2017-01-30
  • 2017-06-14
  • 2017-03-30
  • 1970-01-01
  • 2016-10-04
  • 2015-12-01
  • 1970-01-01
  • 2016-04-29
相关资源
最近更新 更多