添加ui-mask时,初始数据未加载到输入字段

时间:2016-05-11 09:46:13

标签: html angularjs angular-ui

我有下表,

<table class="me-checkbox-table">
    <thead>
    <th class="checkbox-column">
        <md-checkbox md-no-ink  aria-label="Check all"></md-checkbox>
    </th>
    <th>sku#</th>
    <th class="item-name-column">item name</th>
    <th class="id-column">qty</th>
    <th>price</th>
    <th>sale price</th>
    </thead>
    <tbody>
    <tr ng-repeat="inventory in inventoryList">
        <td class="checkbox-row">
            <md-checkbox md-no-ink  aria-label="Check one item"></md-checkbox>
        </td>
        <td ng-model="inventory.sku">{{inventory.sku}}</td>
        <td><a href="" ng-model="inventory.name" ng-click="gotoedit(inventory)">{{inventory.name}}</a></td>
        <td><input type="text" name="quantity" ng-pattern="/[0-9]+/" ui-mask="999" ng-model="inventory.quantity" />
        </td>
        <span class="error" ng-show="allItems.quantity.$error.minlength"></span>
        <td><input type="number" ng-model="inventory.price" /></td>
        <td class="sale-yes"><input type="number" ng-model="inventory.discount" /></td>
    </tr>
    </tbody>
</table>

我使用控制器从后端获取数据,下面是我的控制器,

inventoryService.getInventoryList()
                         .success(function (result) {

                             $scope.inventoryList = result;
                             console.log("result "+result[0]);
                         }).error(function (error) {
                             alert("Inventory Loading Error : " + error);
                         })

当我不在输入字段中添加ui-mask时,Quantity的值正在加载但是当我这样做时,它不会将数据加载到Quantity字段。请帮忙

1 个答案:

答案 0 :(得分:1)

我的created sample只是我的enter image description here,这就是我发现的:

<div ng-app="MyApp">
  <div ng-controller="Controller">
    {{ quantity }}
    <input type="text" name="quantity" ng-pattern="/[0-9]+/" ui-mask="999" ng-model="quantity" />
  </div>
</div>

当我指定0到99之间的值时,ui-mask拒绝它,我看到空输入。

angular.module('MyApp', ['ui.mask'])
  .controller('Controller', function($scope) {
    $scope.quantity = 70;
  });

当我指定100到999之间的值时,它可以正常工作:

angular.module('MyApp', ['ui.mask'])
  .controller('Controller', function($scope) {
    $scope.quantity = 544;
  });