2015-10-14 18 views
0

如何訪問ng網格內的全局Javascript變量?如何訪問ng-grid中的全局Javascript變量?

我有一個全局變量var ShowApprovalLog = "True",我想要在ng-grid cellTemplate中訪問。

{ 
    field: 'Urgent', 
    width:'60px', 
    displayName: 'Urgent', 
    enableSorting: false, 
    cellTemplate: 
     '<div class="ngSelectionCell">{{row.entity.Urgent}} 
     <span ng-if=\"ShowApprovalLog ==\'True\' \"> 
     <img src=\"../Images/Urgent.png\" alt=\"Image\"/></span></div>' 
}, 

回答

0

你爲什麼不把它放在$ rootScope你的模塊的運行區間中?

angular.module('myModule', []). 
config(function(injectables) { // provider-injector 
    // This is an example of config block. 
    // You can have as many of these as you want. 
    // You can only inject Providers (not instances) 
    // into config blocks. 
}). 
run(function(injectables) { // instance-injector 
    // This is an example of a run block. 
    // You can have as many of these as you want. 
    // You can only inject instances (not Providers) 
    // into run blocks 
    $rootScope.ShowApprovalLog = "true" 
}); 

你可以從任何觀點與{{ShowApprovalLog}}訪問值