如何使用 Angularjs 从 json 中删除字符串中的数字?

How to remove numbers in string from json using Angularjs?

我正在研究 Angular。代码中的 Api 通过包含数字和字母的字符串传递 json 值。但我的要求是仅显示字母并从我的下拉列表中的字符串中删除数字。

我的脚本:

staffService.getBaseBranches()
    .success(function(data) {
      $scope.baseBranches = data;

    })
    .error(function(error, status) {
      showError(error, status);
      notificationFactory.error("Unable to load base branches.");
    });

我的 html :

 <div class="form-group">
        <label>Branch : <i class="mandate">*</i></label>
           <select class="form-control input-md" name='branchName' ng-model="query.branchName" ng-options="branch.branchName as branch.branchName for branch in baseBranches">

           <option value="" selected>-- Select Branch --</option>
            </select>
                  <span class="error" ng-show="search_form.branchName.$error.required">Branch is required</span>
</div>

我该怎么做?请帮助我。

您可以 change branchName 通过调用 showName 函数来显示它。 showName 将负责从 string

中删除 digits
ng-options="branch.branchName as showName(branch.branchName) for branch in baseBranches"

代码

$scope.showName = function(branchName ){
   return branchName.replace(/\d+/g, '')
}