2016-05-17 62 views
0

我的第一篇文章,我已經搜索,但無法找到解決方案。角度路由不顯示內部ng視圖

我的路由內容無法在ng-view中看到。

indext.html

<html lang="en" ng-app="myApp"> 
<head> 
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script> 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-route.min.js"></script> 
    <script src="static/js/app.js"></script> 
</head> 
<body> 
<ng-view></ng-view> 

</body> 
</html> 

app.js

var app = angular.module('myApp',[]); 

app.config(['$routeProvider', 

function($routeProvider,$locationProvider) { 

    $locationProvider.html5Mode(true); 
    console.log("Kom till config"); 

    $routeProvider. 
     when('/', {templateUrl: 'static/partials/mainpage.html', 
    }). 
    otherwise({ 
     redirectTo: '/' 
    }); 
}]); 

我沒有得到任何錯誤,不知道怎麼解決,我感謝你的幫助。

文件結構

C:. 
├───.idea 
├───.openshift 
│ ├───action_hooks 
│ ├───cron 
│ │ ├───daily 
│ │ ├───hourly 
│ │ ├───minutely 
│ │ ├───monthly 
│ │ └───weekly 
│ └───markers 
├───static 
│ ├───css 
│ ├───fonts 
│ │ ├───font-awesome 
│ │ │ ├───css 
│ │ │ ├───fonts 
│ │ │ ├───less 
│ │ │ └───scss 
│ │ └───fonts 
│ ├───img 
│ │ ├───client 
│ │ ├───portfolio 
│ │ └───team 
│ ├───js 
│ └───partials 
└───templates 
    ├───admin 
    └───security 

這是一個燒瓶服務器,使該資源到客戶端。

回答

1

你必須添加ngRoute到你的模塊。

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

然後使用$ routeRrovider這樣的:

app.config(['$routeProvider', '$locationProvider', 
    function($routeProvider, $locationProvider) { 
    $locationProvider.html5Mode(true); 
    $routeProvider. 
     when('/', { 
     templateUrl: 'partials/partial.html' 
     }). 
     otherwise({ 
      redirectTo: '/' 
     }); 
    }]); 

在你使用index.html:

<div ng-view></div>