2017-06-17 58 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