2017-05-04 61 views
-1

我使用$ stateprovider頁我給了$ state.go(「廠景」)之間進行切換去使用$狀態頁面加載了在agularjs前一頁

到view1.html

config(['$qProvider','$stateProvider','$locationProvider', '$routeProvider', function($qProvider,$stateProvider,$locationProvider, $routeProvider) { 
    $locationProvider.hashPrefix('!'); 
    $stateProvider 
     .state('index', { 
      url: '/', 
      templateUrl: 'index.html' 
     }) 
     .state('view1', { 
      url: '/view1', 
      templateUrl: 'view1/view1.html', 
      controller:'View1Ctrl' 
     }) 
     .state('view2', { 
      url: '/view2', 
      templateUrl: 'view2/view2.html' 
     }); 
    $routeProvider.otherwise({redirectTo: '/'}); 
    $qProvider.errorOnUnhandledRejections(false); 
}]) 

功能

controller("appcontroller",['$scope','$state','$stateParams',function($scope,$state,$stateParams,$rootScope){ 
$scope.login = function() 
{ 
    $state.go('view1'); 

} 
}]); 

這裏view1.html加載,但其表現的index.html

+0

你能分享inde.html嗎? –

回答

0

上面當你正在使用Anguar UI的路由器。您必須保存在index.html中。所以你的view1.html只會在那裏被替換。 index.html中的其他代碼將不會受到角碼的影響。

<p> Here is me </p> 
<ui-view></ui-view> 

現在,如果你改變了路線。 「這是我」將永遠在那裏。

希望這是我明白的問題。

+0

我試過,因爲你告訴了,但現在它不會去第二頁。 –

+0

你能分享html文件嗎? –

+0

很抱歉,以前的問題沒有了。現在,當第二頁加載它顯示兩次。內容加載兩次。 –