2017-03-02 63 views
0

我想用两个不同的视图和我有两个不同的角色1.客户 2.经理如何在HTML中切换标志的形式(Angular JS)

在我的控制器我增加了基于用户角色已登录的标志。

$scope.userFlag=$rootScope.globalSession.UserRole, 

如果我登录为经理,则该值的$ rootScope.globalSession.UserRole = “经理人”

&如果我登录为客户然后$ rootScope.globalSession.UserRole的价值在我的形式,我添加了一个条件= “客户”

我们打开它 - >NG-IF = “userFlag ==管理员”

 <form class="form-horizontal" name="UpdateAdminProfileForm" id="UpdateAdminProfileForm"> 
      <h2>Update Profile</h2> 
       <hr> 
      <fieldset name="client" id="client" ng-if="userFlag==Admin"> 

       <!-- Text input--> 
       <div class="form-group"> 
        <label class="col-md-4 control-label" for="username">Domain Name*</label> 
        <div class="col-md-4"> 
         <input id="username" name="username" type="text" placeholder="Enter your username" class="form-control input-md" ng-model="theClient.OrganizationDomain" disabled> 

        </div> 
       </div> 

       <!-- Button --> 
       <div class="form-group"> 
        <label class="col-md-4 control-label" for="update"></label> 
        <div class="col-md-4"> 
         <a><button id="update" name="update" class="btn btn-primary" ng-click="updateClient()">Update</button></a> 

        </div> 
       </div> 
      </fieldset> 
      <fieldset name="manager" id="manager" ng-show="userFlag==Manager"> 

       <div class="form-group" ng-class="{ 'has-error': submitted && UpdateAdminProfileForm.myemail.$error.required || UpdateAdminProfileForm.myemail.$error.pattern }"> 
        <label class="col-md-4 control-label" for="myemail">Email*</label> 
        <div class="col-md-4"> 
         <input id="myemail" name="myemail" type="email" placeholder="Enter your email" class="form-control input-md" ng-model="theClient.Email" ng-pattern="regex.Email" ng-maxlength="20" required autofocus > 
         <span ng-show="submitted && UpdateAdminProfileForm.myemail.$error.required" class="help-block">Email can not be empty</span> 
         <span ng-show="UpdateAdminProfileForm.myemail.$error.pattern && UpdateAdminProfileForm.myemail.$invalid " class="help-block">Please enter a valid email</span> 
        </div> 
       </div> 

     <div class="modal-footer"> 
    <button class="btn btn-primary" data-dismiss="modal" type="button" ng-click="updateManager()">Save</button> 
    </div> 
      </fieldset> 
     </form> 
    </div> 
</div> 

但是当我打开窗体,其空它不工作,如果我删除NG-IF = “userFlag ==管理员” & NG-IF =“userFlag ==经理“ from tags然后它显示两个字段集的字段。

图像的FLAG

With Flag

像去除FLAG

enter image description here

帮助后!提前致谢。

回答

1

应该

ng-if="userFlag=='Admin'" 
1

尝试这个

ng-if="userFlag=='Admin'" or ng-show="userFlag=='Manager'"