我正在尝试在 ASP.NET AngularJs 应用程序中路由一个简单的 View ,但未在浏览器 ngView 上加载的 View 已在浏览器中被注释掉。
JavaScript
(function () {
"use strict";
angular.module("app-trips", ["simpleControls", "ngRoute"])
.config(function ($routeProvider) {
$routeProvider.when("/", {
$controller: "tripsController",
$controllerAs: "vm",
$templateUrl: "/views/tripsView.html"
});
$routeProvider.when("/editor", {
$controller: "tripEditorController",
$controllerAs: "vm",
$templateUrl: "/views/tripEditorView.html"
});
$routeProvider.otherwise({ redirectTo : "/"});
});
})();
CHTML
@model IEnumerable<App.Models.Trip>
@{
ViewBag.Title = "Home";
}
@section Scripts{
<script src="~/lib/angular/angular.min.js"></script>
<script src="~/lib/angular-route/angular-route.min.js"></script>
<script src="~/js/simpleControls.js"></script>
<script src="~/js/app-trips.js"></script>
<script src="~/js/tripsController.js"></script>
}
<div ng-app="app-trips">
<div ng-view></div>
</
结果
最佳答案
从 $routeProvider
路由属性中删除 $
符号。
$routeProvider.when("/", {
controller: "tripsController",
controllerAs: "vm",
templateUrl: "/views/tripsView.html"
});
Note: If you're using .NET MVC project, you can't access html files directly from
views
folder. I'd recommend to create a new folder and put static html files there.
关于javascript - 查看未在 Asp.net Angular 应用程序中加载。使用 Asp.net mvc 进行 Angular 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47182702/