gpt4 book ai didi

angularjs - 预输入选择后如何清除字段?

转载 作者:行者123 更新时间:2023-12-02 23:12:41 27 4
gpt4 key购买 nike

使用ui.bootstrap选择 typeahead 提供的选项之一后,如何清除输入的值?

http://plnkr.co/edit/yz4EtEJSTVekSemzxagC?p=preview

var app = angular.module("app", ['ui.bootstrap']);


app.controller('createBundle', ['$scope', '$http', '$location',
function($scope, $http, $location){
$scope.products = [{name: 'One'}, {name: 'Two'}];

$scope.bundle = {
name: '',
products: [],
technologies: [],
deliveryMethods: [],
};

$scope.addProduct = function(item, model, label){
$scope.bundle.products.push(item);
}

$scope.resetProducts = function(){
$scope.bundle.products = [];
}

}]);

HTML

    <input type="text" class="form-control" id="products" 
ng-model="tempProduct"
typeahead="product.name for product in products | filter:$viewValue | limitTo:8"
placeholder="Products" typeahead-on-select="addProduct($item, $model, $label)">

解决方案

typeahead-on-select="addProduct($item, $model, $label);tempProduct=null"

最佳答案

在您的addProduct函数中,您需要清除输入的模型

$scope.addProduct = function(item, model, label){
$scope.bundle.products.push(item);
$scope.tempProduct = null; //-- clear it
}

关于angularjs - 预输入选择后如何清除字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25979163/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com