簡體   English   中英

Angular ngView不顯示頁面

[英]Angular ngView not showing page

當我單擊鏈接加載ngView頁面時,不會顯示html文件。

我沒有通過本地主機運行應用程序,我懷疑這可能是問題所在。 我剛剛用Chrome打開了index.html,所以ngRoute缺少某些依賴項了嗎?


路由器應用/
--- index.html
--- app.js
-頁數/
------- home.html
------- about.html
------- contact.html

無論如何,這是我的app.js

// app.js

// create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function($routeProvider){
    $routeProvider

        //route for home page
        .when('/', {
            templateURL: 'pages/home.html',
            controller: 'mainController'
        })

        //route for home page
        .when('/about', {
            templateURL: 'pages/about.html',
            controller: 'aboutController'
        })

        //route for home page
        .when('/contact', {
            templateURL: 'pages/contact.html',
            controller: 'contactController'
        })

        //default route
        .otherwise({
            redirectTo: '/'
        });
});

// create the controller and inject Angular's $scope
scotchApp.controller('mainController', function($scope) {

    // create a message to display in our view
    $scope.message = 'Everyone come and see how good I look!';
});

scotchApp.controller('aboutController', function($scope){
    $scope.message = 'Look! I am on the About page!';
});

scotchApp.controller('contactController', function($scope){
    $scope.message = 'Shoutout! I am on the Contact page!';
});

這是index.html

<!-- index.html -->
<!DOCTYPE html>
<html ng-app='scotchApp'>
<head>

  <BASE href="/Users/Khan/Desktop/router-app/">
  <!-- SCROLLS -->
  <!-- load bootstrap and fontawesome via CDN -->
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" />

  <!-- SPELLS -->
  <!-- load angular and angular route via CDN -->
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
  <script src="script.js"></script>

  <meta charset='utf-8'>
  <base href='/'>
</head>
<body>

    <!-- HEADER AND NAVBAR -->
    <header>
        <nav class="navbar navbar-default">
        <div class="container">
            <div class="navbar-header">
                <a class="navbar-brand" href="/">Angular Routing Example</a>
            </div>

            <ul class="nav navbar-nav navbar-right">
                <li><a href="#"><i class="fa fa-home"></i> Home</a></li>
                <li><a href="#about"><i class="fa fa-shield"></i> About</a></li>
                <li><a href="#contact"><i class="fa fa-comment"></i> Contact</a></li>
            </ul>
        </div>
        </nav>
    </header>

        <!-- angular templating -->
        <!-- this is where content will be injected -->
        <div ng-view></div>

</body>
</html>

如果有人知道,我對正在發生的事情很好奇。 謝謝您的幫助! :)

從模板網址中刪除前導斜杠,

/Pages/about.html

應該成為

Pages / about.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM