2017-03-02 43 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'"