Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在angular js中为ui-select2添加新选项_Jquery_Angularjs_Jquery Select2_Ui Select2_Angularjs Select2 - Fatal编程技术网

Jquery 在angular js中为ui-select2添加新选项

Jquery 在angular js中为ui-select2添加新选项,jquery,angularjs,jquery-select2,ui-select2,angularjs-select2,Jquery,Angularjs,Jquery Select2,Ui Select2,Angularjs Select2,我在angularjs中使用ui-select2,它使用jquery的select2插件。我有一些预定义的列表,然后当我开始搜索任何东西时,如果在列表中找不到,我想添加一个新值。我正在做这样的事情: var selectOptions = { formatNoMatches: function(term) { return "<a ng-click=\"addCountry('abc');\">Add new country</a>

我在angularjs中使用ui-select2,它使用jquery的select2插件。我有一些预定义的列表,然后当我开始搜索任何东西时,如果在列表中找不到,我想添加一个新值。我正在做这样的事情:

var selectOptions = {
    formatNoMatches: function(term) {
                return "<a ng-click=\"addCountry('abc');\">Add new country</a>";
            }
 };

 $scope.addCountry = function(countryName) {
    console.log (' test');
 };
var selectOptions={
formatNoMatches:函数(术语){
返回“添加新国家”;
}
};
$scope.addCountry=函数(countryName){
console.log('test');
};

但是点击不起作用,addCountry中的控制台永远不会打印出来。你知道如何在angular js中为ui-select2添加新选项吗?

我这样做了,不是通过单击,而是通过允许用户在select2中输入他们喜欢的内容,然后按enter键:

<input type="text" ui-select2="selectOpts" ng-model="selected"/>
我希望这能让你走上正轨,最基本的是设置“标签:正确”

将Select2置于“标记”模式,用户可以在该模式下添加新选项和 通过此选项属性提供预先存在的标记,该属性为 或者

和createSearchChoice(在中搜索此项):

从用户的搜索词中创建新的可选选项。允许创建通过查询功能不可用的选项。当用户可以动态地创建选择时非常有用,例如“标记”用例


我很确定ng click不起作用,因为这段代码不是由angularjs编译的,因为您在运行时输出它。。。你能给我们提供一把木棍或小提琴吗?它将帮助我们从您已有的内容中找到解决方案;
  $scope.selectOpts =
    maximumSelectionSize: 1
    data: $scope.someListOfData
    tags: true
    multiple: false
    createSearchChoice: (term) ->
      {id: term, text: term}