首页 > 解决方案 > ng-view 未显示在 index html 页面中

问题描述

我的目标是在网络应用程序上做路由页面。我写了两页:索引和主页。在索引页面中,有调用主页的 ng-view。但浏览器不显示任何主页。也许我写 script.js 是错误的......

索引.html:

<body ng-controller="productsCtrl">
        <header ng-include="'header.html'"></header>            
            <div id="main">

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

            </div>
        </body>

脚本.js:

var app = angular.module('myApp', ['ngRoute']);

app.config(['$routeProvider', function($routeProvider){

    $routeProvider
    .when('/home', {
        templateUrl: '../templates/home.html'
    })

    .otherwise({
        redirectTo: '/home'
    });
}]);

有人可以帮助男人解决这个问题。谢谢

标签: javascripthtmlangularjs

解决方案


你必须使用 ng-app 指令

<body ng-app="myApp">

推荐阅读