如何通过在角度

时间:2018-02-02 11:42:59

标签: angularjs angularjs-material

每当用户点击它时,我想在输入字段中添加一个字符串,我怎么能用角度来做 这是html片段

<md-input-container class="md-icon-float md-block">
  <label>Dripo #id</label>
  <md-icon class="md-default-theme" class="material-icons">&#xE30E;</md-icon>
  <input ng-model="manageDripo.dripoData.dripoid" type="text" name="dripoid" ng-pattern="/^[A-Za-z0-9]+((,|-)[A-Za-z0-9]+)*[A-Za-z0-9]+$/" required>
  <a ng-repeat="driponame in driponames">{{driponame}}</a>
</md-input-container>

和ManageDripo Controller已

.controller('manageDripoCntrl',function ($http,$window,$location,$timeout,$mdDialog,$scope,Admin) {
  $scope.driponames = [DRIPO-123,DRIPO-8987];

  ....
});

1 个答案:

答案 0 :(得分:1)

考虑到AngularJs的双向竞标以及你的ng-model,你需要在ng-model关联的变量上插入你想要的给定字符串,在你的案例中manageDripo .dripoData.dripoid。

所以在html中输入:

<input ng-model="manageDripo.dripoData.dripoid" ng-click="insertString()" type="text" name="dripoid" ng-pattern="/^[A-Za-z0-9]+((,|-)[A-Za-z0-9]+)*[A-Za-z0-9]+$/" required>

在控制器上:

.controller('manageDripoCntrl',function ($http,$window,$location,$timeout,$mdDialog,$scope,Admin) {
  $scope.driponames = [DRIPO-123,DRIPO-8987];

  $scope.insertString = function () {
    $scope.manageDripo.dripoData.dripoid += 'The String you want';
  };
  ....
});