2017-07-28 39 views
0

私はangularJSのルーティングを練習しており、問題に直面しています。私はオンラインで見て、多くの方法を試しましたが、それは私の問題を解決しません。手伝って頂けますか?

$ state.go関数に問題があります。それはurlを変更しますが、htmlファイルはロードされません。私は、コンソールに見えたが、エラーが

app.js

(function(){ 
    var app = angular.module('myTrello', 
    ['date-directives', 'ngRoute', 'ui.router']); 

    app.controller("mainCtrl", ['$scope', '$http', '$state', '$route', function($scope, $http, $state, $route){ 
    $scope.title = "Welcome to my trello"; 
    $http.get("http://quotes.rest/qod.json") 
    .then(function(response) { 
     let quoteInfo = response.data.contents.quotes[0]; 
     $scope.quote = quoteInfo.quote; 
     $scope.author = quoteInfo.author; 
    }); 
    $scope.go = function(path) { 
     $state.go(path, {}); 
    }; 
}]); 

app.controller("boardCtrl", function(){ 

}); 

// app.controller("routeCtrl", function($scope, $routeParams) { 
//  $scope.param = $routeParams.param; 
// }); 

app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider){ 
    $urlRouterProvider.otherwise('/home'); 
    $stateProvider 
     .state('home', { 
      url: '/home',   
      templateUrl: 'index.html', 
      controller: 'mainCtrl' 
     }) 
     .state('boards', { 
      url: '/boards', 
      templateUrl: 'boards/board.html', 
      controller: 'boardCtrl' 
     }) 
     // .state('/boards/:param', { 
     //  url: '/boards/:param', 
     //  templateUrl: 'index.html', 
     //  //controller: 'boardCtrl' 
     // }) 
}]); 
})(); 

index.htmlを(重要な部分)

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
<script src="bower-angular-route/angular-route.js"></script> 
<script src="https://unpkg.com/[email protected]/release/angular-ui-router.min.js"></script> 

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
<link rel="stylesheet" href="style.css" /> 
<script src="app.js"></script> 
<script src="date.js"></script> 

<body ng-controller="mainCtrl"> 
    <div class="container"> 
     <div class="jumbotron"> 
      <div class="title"> 
       <h2 class="text-center">{{title}}</h2> 
      </div> 
     </div> 
     <div class="bg-1 text-white text-center"> 
      <h3>Today's quote</h3> 
      <h4>{{quote}}</h4> 
      <h5>By: {{author}}</h5> 
     </div> 
    </div> 
    <button class="btn btn-info btn-lg boards" ng-click="go('boards')">My boards</button> 
    <div ng-view></div> 
    </body> 

board.html

<html> 
<h1>Boards</h1> 
</html> 

答えて

1

ように表示されませんui-routerを使用しています。を使用する必要があります代わりng-viewの指令、そう

<div ui-view></div> 

代わりに

<div ng-view></div> 
ようにコードを変更します
関連する問題