2017年5月8日 星期一

ng-options 正確顯示空白字元且不要被合併

必須把空白字元轉成 String.fromCharCode(160),無法使用   或標準空白(ascii 32)
  於 ng-options 中會直接顯示成  
標準空白於 html 中連續出現則會自動合併
ascii 160 表示不換行空格,同時具備不會於 html 中自動被合併的特性
不換行空格 - 維基百科

javascript
====
angular.module('commonModule', []).service('commonService', function () {
    var self = this;
    self.replaceSpaces = function (str) {
        return str.replace(/ /g, String.fromCharCode(160));
    };
});
angular.module('module1', ['agGrid', 'ui.bootstrap', 'fiestah.money', 'commonModule'])
.controller('detailCtrl', function ($scope, $http, $window, $filter, $timeout, $uibModalInstance, commonService) {
        $scope.commonService = commonService;


html
====
<select style="font-family:MingLiU !important" class='form-control' ng-change="selectATLINK(1)" ng-model='selectData.ATLINKObject_1' ng-options='commonService.replaceSpaces(a.text) for a in selectData.atlinks_1' ng-show='selectData.atlinks_1.length>0'>

沒有留言:

自訂權限驗證機制

// 使用 filter [Route("api/[controller]")] [ApiController] [Authorize] [TypeFilter(typeof(CustomAsyncAuthorizationFilter))] public c...