0
我有一個按鈕只能用於「管理員」類型的用戶。因此,我驗證了登錄系統的用戶的權限組,並確定是否顯示/ hdie按鈕。所以我嘗試,ng-if/ng-show/ng-hide,沒有任何工作......我作爲監視器登錄,並且按鈕不可用。控制器內的HIde按鈕裏面的列定義
我的代碼:
app.controller('OrganizationsController',['$rootScope', '$scope', '$modal', 'HelperService', 'AuthService', '$state', '$http', function ($rootScope, $scope, $modal, HelperService, AuthService, $state, $http) {
var controllerScope = $scope;
controllerScope.organizationsData = {};
controllerScope.organizationsData.ajax = {url:'/api/organizations/', dataSrc:''};
controllerScope.organizationsData.ajax.beforeSend = function (xhr) {
xhr.setRequestHeader("Authorization", AuthService.authToken());
}
controllerScope.permissionGroup=$rootScope.permissions.group_name;
controllerScope.organizationsData.columns = [
{"data":null,"render":function(data) {
return '<a href="/#/organization/'+data.id+'">'+data.data.name+'</a>';
}},
{"data":"domain","defaultContent":""},
{"data":null, "orderable":false, "render":function(data){
return '<button class="btn btn-default btn-sm" style="margin-right:5px;" ng-if="controllerScope.permissionGroup.indexOf(\'Administrator\')!==-1" onclick="angular.element(this).scope().openOrganizationPermissionsSettings(\''+data.id+'\')"><i class="fa fa-wrench"></i></button>'
+'<button class="btn btn-default btn-sm" style="margin-right:5px; " onclick=\'angular.element(this).scope().openNewOrganizationModal('+JSON.stringify(data)+')\'><i class="fa fa-pencil"></i></button>'
+'<button class="btn btn-default btn-sm" onclick="angular.element(this).scope().deleteOrganization(\''+data.id+'\')"><i class="fa fa-trash"></i></button>';
}}];
controllerScope.deleteOrganization = function (organizationId) {
HelperService.deleteItem(organizationId, 'organization', '/api/organizations/');
};
所以最重要的線路有:
controllerScope.permissionGroup=$rootScope.permissions.group_name
返回 「監視器」
和
<button class="btn btn-default btn-sm" style="margin-right:5px;"
data-if="controllerScope.permissionGroup.indexOf(\'Administrator\')!==-1" onclick="angular.element(this).scope().openOrganizationPermissionsSettings(\''+data.id+'\')">
<i class="fa fa-wrench"></i></button>'
,我創建按鈕和管理其知名度。
現在按鈕始終可用作爲上面的圖像。
只要使用ng-if?如何使用$ compile? –
@AndréBastos根本沒有,所有的角度指令應編譯 –
對我來說很簡單,使用ng-if ..如何用ng-if做到這一點?例如..如果我使用ng-.click onclick事件不彈出,而不是onclick它的工作... –