[英]Angularjs routing not working with controller and model using IIF funtion
我用路由配置創建了一個簡單的網站。 我正在為模塊和控制器使用IIF javascript,但是路由不起作用。
僅當我鍵入默認的本地主機(例如http://localhost:18689
此方法http://localhost:18689
但是,如果嘗試http://localhost:18689/maindashboard
任何路由http://localhost:18689/maindashboard
或$location.path('/addrequest')
,則得到404。
IIF可能是問題嗎?
我的模塊是這樣的:
(function () {
"use strict";
var clientAppModule = angular.module('clientAppModule', ["ngRoute", "ui.bootstrap", "ngResource"]);
clientAppModule.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when("/maindashboard", {
templateUrl: "app/maindashboard/maindashboard.html",
controller: "mainDashboardController"
})
.when("/addrequest", {
templateUrl: "app/addrequest/addrequest.html",
controller: "addRequestController"
})
.otherwise({
redirectTo: "/maindashboard"
});
$locationProvider.html5Mode(true);
});
}());
索引頁:
<!DOCTYPE html>
<html ng-app="clientAppModule">
<head>
<title></title>
<!-- CSS -->
<link href="Content/css/font-awesome.css" rel="stylesheet" />
<!-- Libraries -->
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular-route.min.js"></script>
<script src="Scripts/angular-resource.min.js"></script>
<script src="Scripts/angular-ui/ui-bootstrap-tpls.min.js"></script>
<!-- Code -->
<script src="App/clientAppModule.js"></script>
<script src="App/Index/indexController.js"></script>
<script src="App/MainDashboard/mainDashboardController.js"></script>
<script src="App/AddRequest/addRequestController.js"></script>
<base href="/">
</head>
<body class="container">
<h1>New Turning Point and Care Point Test Frame</h1>
<div>
<br /> 3 + 5 =
{{3+5}}
<br />
</div>
<div ng-view>
</div>
</body>
</html>
儀表板的主要控制器是:
(function () {
'use strict';
var mainDashboardController = function ($scope) {
$scope.TestObj = 'testmainDashboardController';
$scope.showAddRequest = function () {
$location.path('/addrequest');
};
};
var app = angular.module('clientAppModule');
app.controller("mainDashboardController", mainDashboardController);
})();
addrequest控制器類似於一個測試
您的問題是您在mainDashboardController
缺少$location
參數
var mainDashboardController = function ($scope, $location)
另外,如果計划最小化代碼,則在使用任一內聯語法創建控制器時都應聲明依賴項
app.controller('mainDashboardController', ['$scope', '$location', mainDashboardController]);
或角度噴射器
mainDashboardController.$inject = ['$scope', '$location']
這樣,當最小化器將您的參數名稱更改為a
或b
或其他名稱時,angular將知道它們應該是什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.