如何使用angular分割输入文本框值

时间:2017-02-15 11:58:17

标签: html angularjs

我有san值,如何将此值拆分为三个部分 例如"<HR>*10/100""HR", "*"

HTML

"10/100"

 <input type='text' ng-model='value' ng-change="GetAngValue(value)">
                            {{Result}}

使用此代码获取尖括号值,但如何获取剩余的

2 个答案:

答案 0 :(得分:0)

这很长的路要走,但它会做到这一点

value.replace("<","").replace(">",",").replace("*","*,").split(",");

答案 1 :(得分:0)

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
<div ng-app="app" ng-controller="appCtrl">
  <input type='text' ng-model='value' ng-change="GetAngValue(value)">
                            {{Result}}
</div>

<script>
angular.module('app',[]).controller('appCtrl',function($scope){
$scope.GetAngValue = function (value) {
    var Matches = value.replace("<","").replace(">",",").replace("*","*,").split(",");
  
    if (Matches) {
        $scope.Result = Matches;
    }
  console.log(Matches);
}

})


</script>
&#13;
&#13;
&#13;