ng-view不会被html取代

时间:2014-03-20 06:01:35

标签: javascript node.js angularjs

我在app.js中配置了路由:我的根路径是http://127.0.0.1:3000/admin。所以当我点击#/ stock / new时,它会转到http://127.0.0.1:3000/admin#/stock/new。这是对的吗?

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

aomaika.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
    .when('/stock/new', { templateUrl: 'partials/new.html', controller: 'StockNewCtrl'})
    .when('/', { templateUrl: 'partials/index.html', controller: 'DashboardCtrl'})
    .otherwise({redirectTo: '/'});
}]);

并在index.jade

doctype html
html(lang="en" ng-app='aomaika')
    head
        title= title
        meta(name='description', content='overview & stats')
        meta(name='viewport', content='width=device-width, initial-scale=1.0')
        link(rel='stylesheet', href='/assets/css/bootstrap.min.css')

        script(src='//ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js')
        script(src='//ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular-resource.min.js')
        script(src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')
        script(src="js/app.js")
        script(src="js/controllers.js")
        script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular-route.js")

    body(ng-controller="StockCtrl")
        div#main-container.main-container
            a(href="#/stock/new") New Stock
            div(ng-view)

但是当点击New Stock为#/ stock / new时,partials / new.html不会插入到ng-view中。到底发生了什么?为什么会出现#"#"之前/库存/新。那是什么?

1 个答案:

答案 0 :(得分:0)

您正在呼叫StockCtrl,但在您的JS中,您正在引用StockNewCtrl

你的控制器代码在哪里?

请,只需要编译HTML,而不是玉代码......