簡體   English   中英

ui-router-ui視圖和鏈接不起作用

[英]ui-router - ui view and link not working

我正在嘗試ui路由器的角度。 我將以下代碼行添加到我的app.js中的應用程序模塊中:

angular
 .module("ngClassifieds", ['ngMaterial', 'ui.router'])
 .config(function($mdThemingProvider, $stateProvider){

    $mdThemingProvider.theme('default')
        .primaryPalette('teal')
        .accentPalette('orange');

    $stateProvider
        .state('stateone', {
            url:'/stateone',
            template: '<h1>State one</h1>'
        })
        .state('statetwo', {
            url: '/statetwo',
            template: '<h1>State two</h1>'
        });

});

在我的html上,我只是放置一個空的ui視圖以測試我是否正在獲取這兩個標頭,但沒有運氣:

<ui-view></ui-view>

通過輸入以下內容在我的localhost鏈接上進行測試:

localhost:8080/#/stateone
localhost:8080/#/statetwo

但是由於某些原因,它不會在任何鏈接中加載/顯示任何標題,而只是顯示沒有標題的頁面。

我已經將angular-ui-router.js包含在我的index.html中

如果有人能指出我做錯了,那太好了。

如果有人想知道:這是我的腳本的順序:

  <script src="node_modules/angular/angular.js"></script>
  <script src="node_modules/angular-animate/angular-animate.js"></script>
 <script src="node_modules/angular-aria/angular-aria.js"></script>
 <script src="node_modules/angular-material/angular-material.js"></script>
 <script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script>

 <script src="scripts/app.js"></script>

 <script src="components/classifieds.ctr.js"></script>
 <script src="components/classifieds.fac.js"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>

由於您沒有收到任何錯誤,因此很難理解出了什么問題,但是您可以看看我的plunkr並找出來。 我刪除了棱角材料。

https://plnkr.co/edit/WGjzY6flSx5Ces1moSPk?p=preview

    <script>
    angular
 .module("ngClassifieds", ['ui.router'])
 .config(function( $stateProvider){

    $stateProvider
        .state('stateone', {
            url:'/stateone',
            template: '<h1>State one</h1>'
        })
        .state('statetwo', {
            url: '/statetwo',
            template: '<h1>State two</h1>'
        });

});
    </script>
  </head>

  <body>
    <h1>Hello Plunker!</h1>
    <a href="#/stateone">Link1</a>
     <a href="#/statetwo">Link2</a>
     <ui-view></ui-view>
  </body>

暫無
暫無

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

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