页面未在Angular中更新

时间:2017-01-25 14:27:51

标签: angularjs

我正在创建一个使用角度(学习)的测试项目网站,当我点击index.html页面上的测试时,ng-view不会更新。我一直在网上寻找最近​​2个小时,尝试了几个解决方案,没有任何效果。请帮助我做错了!!!

的index.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <!-- Angular References -->
    <script src="Scripts/angular.min.js"></script>
    <script src="Scripts/jcs-auto-validate.min.js"></script>
    <script src="Scripts/angular-route.min.js"></script>
    <!-- Bootstrap Core CSS -->
    <script src="Scripts/jquery-1.9.1.min.js"></script>
    <script src="Scripts/bootstrap.min.js"></script>
    <link href="Content/bootstrap.min.css" rel="stylesheet" />
    <link href="Content/font-awesome.min.css" rel="stylesheet" />
    <!-- CSLMS App Angular References -->
    <script src="CSLMS_app/app.js"></script>
    <script src="CSLMS_app/Recipe_Values/ConstantValues.js"></script>
    <script src="CSLMS_app/Controllers/indexController.js"></script>
    <!-- Style Sheets -->
    <link href="Content/Site.css" rel="stylesheet" />
</head>
<body ng-app="CSLMS_app">
    <div ng-controller="indexController">
        <!-- Top Navigation -->
        <nav class="navbar navbar-dark bg-primary navbar-fixed-top" >
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">CS-LMS</a>
                </div>  <!-- /.navbar-header -->
                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="navbar-collapse collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li><a class="navbar-brand" href="#">Dashboard</a></li>
                        <li><a class="navbar-brand" href="#/Test">Test</a></li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li class="dropdown">
                            <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{user.username}}<span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="javascript:;">Links</a></li>
                                <li><a href="javascript:;">Edit Profile</a></li>
                                <li role="separator" class="divider"></li>
                                <li><a href="javascript:;">Logout</a></li>
                            </ul>
                        </li>
                    </ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
        </nav>

        <div ng-view></div>

    </div>
</body>
</html>

的test.html

<div ng-controller="TestController">
    <h1>test Pagerr</h1>
    <br />
    {{message}}

    <script src="../CSLMS_app/Controllers/testController.js"></script>
</div>

app.js

'use strict';

//var app = angular.module('CSLMS_app', ['jcs-autoValidate', 'ngRoute']);
var app= angular.module('CSLMS_app', ['jcs-autoValidate', 'ngRoute']);


app.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
    .when("/Login", {
        templateUrl: "Pages/Login.html",
        controller: "loginController"
    })
    .when("/Test", {
        templateUrl: "Pages/Test.html",
        controller: "testController"
    })
    .otherwise({ redirectTo: '/Test' })
}]);

testController.js

'use strict';
app.controller('testController', ['$scope', '$route', function ($scope, $route) {
    $scope.message = "Test ";
}])

indexController.js

'use strict';
app.controller('indexController', ['$scope', function ($scope) {
    $scope.somedata = "That";
}]);

2 个答案:

答案 0 :(得分:0)

这里只是一个猜测,但你可能想要移动它:

<script src="../CSLMS_app/Controllers/testController.js"></script>

退出Test.html并进入index.html的<head>元素。我怀疑这是一个问题。可能会有更多,但我至少会这样做。

答案 1 :(得分:0)

您忘记为testController加载脚本。将此行添加到index.html:

<script src="CSLMS_app/Controllers/testController.js"></script>