2017-06-17 39 views
0

在我的應用程序已經宣佈Master.html NG-app並在其 添加的所有腳本,樣式表引用這是我的母版頁如何使用AngularJS

<html ng-app="mainApp"> 
<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <title>AdminLTE 2 | Dashboard</title> 

    <script src="../Angular/angular.min.js"></script> 
    <script src="../Angular/angular-route.js"></script> 
    <script src="../Scripts/AngularServices/App.js"></script> 
</head> 
<body class="hold-transition skin-blue sidebar-mini"> 
         <li><a href="/main/Group"><i class="fa fa-circle-o"></i>Group</a></li> 
            <li><a href="/main/Member"><i class="fa fa-circle-o"></i>Member</a></li> 
<section class="content"> 
           <div ng-view></div> 
          </section> 

</body> 
</html> 

保持母版頁頁面重載的HTML App.js

var mainApp = angular.module("mainApp", ['ngRoute']) 

mainApp.config(function ($routeProvider, $locationProvider) { 
    $routeProvider.when('/main/Group', { templateUrl: '/Portal/Group.html', controller: 'GroupController' }), 
    $routeProvider.when('/main/Member', { templateUrl: '/Portal/Member.html', controller: 'MemberController' }); 
    $locationProvider.html5Mode(true); 
}); 

// group 
mainApp.controller('GroupController', function ($scope, $http) { 
    $http.get('/api/APIGroup/GetGroupDetails').then(function (result) { 
     $scope.group = result.data; 
    }); 
}); 

Group.html

<div ng-controller="GroupController"> 
    <div class="row"> 
<h1>Welcome to group</h1> 
my content here 
</div> 
</div> 

當我執行主PAG Ë如果母版頁中點擊鏈接組形式group.html開我的網址這樣

http://localhost:50810/main/chitGroup 

但如果重載頁面在這裏我得到誤差

Server Error in '/' Application. 
The resource cannot be found. 

母版頁不適用於如何解決這個問題

+0

請參考[本指南](https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-與-html5mode)。 – 31piy

回答

0

在你的angular.app你有ngRoute來處理你的狀態創建Single Page Application

ngRoute需要正確地通過國家名稱爲ng-href="#!/main/Group",因爲當你使用ngRoute網址全自動改爲http://localhost:50810/#!/

Server Error in '/' Application. 
The resource cannot be found. 

這個錯誤,因爲你重定向到http://localhost:50810找到/main/Group其不存在。

+0

我改變了這樣的

  • Chit Group
  • Chit Member
  • ,但它不工作我不是得到錯誤,但我的HTML頁面沒有加載,我的網址是這樣的http://本地主機:50810 /門戶/ Master.html#%2Fmain%! 2FchitGroup – Srinu

    +0

    我沒有看到它,你想在你的應用程序中使用'html5Mode'嗎? – Maher

    +0

    我已經在app.js $ locationProvider.html5Mode(true); – Srinu