如何通过在 angular 中单击将字符串绑定或添加到输入字段
How to bind or add a string to an input field by clicking it in angular
我想在用户单击时向输入字段添加一个字符串,我该怎么做 angular
这是 html 部分
<md-input-container class="md-icon-float md-block">
<label>Dripo #id</label>
<md-icon class="md-default-theme" class="material-icons"></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('manageDripoCntrl',function ($http,$window,$location,$timeout,$mdDialog,$scope,Admin) {
$scope.driponames = [DRIPO-123,DRIPO-8987];
....
});
考虑到 AngularJs 的双向出价,并且你的有 ng-model,你需要点击 ng-click 在与 ng- 关联的变量中插入你想要的给定字符串模型,在你的例子中 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';
};
....
});
我想在用户单击时向输入字段添加一个字符串,我该怎么做 angular 这是 html 部分
<md-input-container class="md-icon-float md-block">
<label>Dripo #id</label>
<md-icon class="md-default-theme" class="material-icons"></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('manageDripoCntrl',function ($http,$window,$location,$timeout,$mdDialog,$scope,Admin) {
$scope.driponames = [DRIPO-123,DRIPO-8987];
....
});
考虑到 AngularJs 的双向出价,并且你的有 ng-model,你需要点击 ng-click 在与 ng- 关联的变量中插入你想要的给定字符串模型,在你的例子中 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';
};
....
});