Home  >  Q&A  >  body text

angular.js - angular-ui-router为什么不能加载视图?

<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <title>Title</title>
    <script src="node_modules/angular/angular.min.js"></script>
    <script src="node_modules/angular-ui-router/release/angular-ui-router.min.js"></script>
</head>
<body>
<p ui-view></p>
<script>
    var app = angular.module('app', ['ui.router']);
    app.config(function($stateProvider, $urlRouterProvider){
        $urlRouterProvider.otherwise('/a/b');
        $stateProvider
                .state('a', {
                    url: '/a'
                })
                .state('a.b', {
                    url: '/b',
                    template: '<p>This is b</p>'
                })
    });
</script>
</body>
</html>
为什么我打开页面后,地址是http://localhost:63341/firecontrol/test.html#/a/b,但是没有东西出来呢?template: '<p>This is b</p>'好像没有效果,控制台没报什么错啊?
黄舟黄舟2700 days ago713

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-05-15 17:01:29

    a configuration inside

    .state('a', {
        url: '/a',
        template:'<p ui-view></p>'
    })

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-15 17:01:29

    You need to configure the following attributes in a:

    .state('a', {
        url: '/a',
        abstract: true
    })

    Hope it helps~ :)

    reply
    0
  • Cancelreply