我是Angualr Js的新手,我正在尝试实现一个简单的应用程序,以下是我的要求,
最初我使用ng-include通过调用我的控制器中的方法来渲染我的视图,该方法命中服务并获得角色并基于角色,我将返回视图。
<html>
<head>
<meta charset="ISO-8859-1">
<title></title>
</head>
<body>
<div class="container" data-ng-app="vendorPortalApp" data-ng-controller="vendorPortalController">
<div data-ng-include="getView()">
</div>
</div>
</body>
我正在将角度服务和控制器与路线一起初始化 的 app.js
angular.module('vendorPortalApp', ['vendorPortalApp.controllers','vendorPortalApp.services','ngRoute']).config(['$routeProvider', function($routeProvider) {
$routeProvider.
when("/home", {controller: "vendorPortalController"}).
when("/home/resetPassword", {templateUrl: "features/resetPassword.html", controller: "vendorResetPasswordController"}).
when("/home/editProfile",{templateUrl: "features/editProfile.html",controller:"vendorEditProfileController"}).
otherwise({redirectTo: '/home'});}]);
Controller.js
angular.module('vendorPortalApp.controllers', []).controller('vendorPortalController', function($scope,serviceApi) {
$scope.role = null;
serviceApi.getUserSessionData().success(function (response) {
$scope.role = response;
});
$scope.getView = function() {
if($scope.role == "SuperAdmin"){
return "views/SuperAdmin.html";
}else if($scope.role == "Admin"){
return "views/Admin.html";
}else if($scope.role == "User"){
return "views/User.html";
}else {
return null;
}
}}).controller('vendorResetPasswordController',function($scope,serviceApi){
}).controller('vendorEditProfileController',function($scope,serviceApi){
});
视图/ SuperAdmin.html
<div class="left-content">
<a href="#/home/editProfile">Edit Profile</a>
<a href="#/home/resetPassword">Reset Password</a>
</div>
<div class="right-content">
<ng-view></ng-view>
</div>
&#13;
我有一个名为features的文件夹,其中我有editProfile.html,以及resetPassword.html部分视图,我想在锚点上呈现这些部分视图点击SuperAdmin.html
editProfile.html
<section data-ng-controller="vendorEditProfileController">
<h1>Edit Profile</h1>
Firstname : <input type="text" name="firstname"/>
Lastname : <input type="text" name="lastname"/>
<input type="submit" value="Submit" />
</section>
&#13;
ResetPassword.html
<section data-ng-controller="vendorResetPasswordController">
<h1> Reset Password </h1>
Password : <input type="password" name="reset-password">
Confirm Password : <input type="password" name="confirm password">
<input type="submit" value="Submit"/>
</section>
&#13;
我能够根据角色渲染视图,一旦SuperAdmin.html视图被渲染,我在页面上有很少的锚链接,在每个锚链接上它引用#/ home / editProfile和#/ home / resetPassword ,这些url模式在路径配置中匹配,并从features文件夹中呈现相应的功能。
我面临的唯一问题是,让我说我点击了重置密码链接,我的网址更新为http://locahost/vendorapp/home.html#/home/resetPassword 并且我获得了在我的页面上呈现的重置密码功能,现在当我重新加载页面时,它给我一个问题,它消除了resetPassword.html功能,即使我们点击重置密码链接,它也不会生成视图。任何有关这方面的帮助将不胜感激!