繁体   English   中英

使用IIF功能的AngularJS路由不适用于控制器和模型

[英]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']

这样,当最小化器将您的参数名称更改为ab或其他名称时,angular将知道它们应该是什么。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM