Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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
Angularjs NGTAGSIN在表单中输入自动完成并添加到数据库_Angularjs_Ng Tags Input - Fatal编程技术网

Angularjs NGTAGSIN在表单中输入自动完成并添加到数据库

Angularjs NGTAGSIN在表单中输入自动完成并添加到数据库,angularjs,ng-tags-input,Angularjs,Ng Tags Input,我一直在尝试使用ngTagsInput及其html表单中的自动完成功能(mbenford.github.io/ngTagsInput/demos)在Mongodb中提交食谱 基本上,我使用ngTagsInput和Autocomplete查询我的配料数据库,并在“配方中的配料”中显示配料标签 它很好用,直到我保存了食谱,而配料没有保存 我知道问题在哪里,但我还没有找到解决办法。 这是我的添加配方页面的“配料”字段,没有ngTagsInput,只是一个普通的文本字段: <div class="

我一直在尝试使用ngTagsInput及其html表单中的自动完成功能(mbenford.github.io/ngTagsInput/demos)在Mongodb中提交食谱

基本上,我使用ngTagsInput和Autocomplete查询我的配料数据库,并在“配方中的配料”中显示配料标签

它很好用,直到我保存了食谱,而配料没有保存

我知道问题在哪里,但我还没有找到解决办法。 这是我的添加配方页面的“配料”字段,没有ngTagsInput,只是一个普通的文本字段:

<div class="form-group">
            <label for="ingredients">List of ingredients</label>
            <input type="text" class="form-control" id="ingredients" ng-model="form.ingredients">
        </div>
你知道我该如何解决这个问题并保存那些标签吗


提前谢谢各位。我不想这篇文章太长,但如果你需要更多的信息,代码,我会非常被动地提供它。这对我有很大帮助。

我在另一篇帖子中找到了一个解决方案:

基本上,我无法保存这些标记,因为ng模型在
标记中不起作用。因此,我使用这个家伙的指令将
更改为一个属性:

<div elem-as-attr="tags-input"></div>

这是指令代码

app.directive('elemAsAttr', function($compile) {
return {
restrict: 'A',
require: '?ngModel',
replace: true,
scope: true,
compile: function(tElement, tAttrs) {
  return function($scope) {
    var attrs = tElement[0].attributes;

    var attrsText = '';
    for (var i=0; i < attrs.length; i++) {
      var attr = attrs.item(i);
      if (attr.nodeName === "elem-as-attr") {
        continue;
      }
      attrsText += " " + attr.nodeName + "='" + attr.nodeValue + "'";        
    }

    var hasModel = $(tElement)[0].hasAttribute("ng-model");
    var innerHtml = $(tElement)[0].innerHTML;
    var html = '<' + tAttrs.elemAsAttr  + attrsText + '>' + innerHtml + '</' + tAttrs.elemAsAttr + '>';

    var e = hasModel ? $compile(html)($scope) : html;
    $(tElement).replaceWith(e);
  };
}
}
});
app.directive('elemAsAttr',function($compile){
返回{
限制:“A”,
要求:“?ngModel”,
替换:正确,
范围:正确,
编译:函数(远程通讯、tAttrs){
返回函数($scope){
var attrs=tElement[0]。属性;
var attrsText='';
对于(变量i=0;i

我不认为这是最佳的,但以我目前的代码知识,我很感谢我找到了这个解决方案。✌ 我在另一篇帖子中找到了解决方案:

基本上,我无法保存这些标记,因为ng模型在
标记中不起作用。因此,我使用这个家伙的指令将
更改为一个属性:

<div elem-as-attr="tags-input"></div>

这是指令代码

app.directive('elemAsAttr', function($compile) {
return {
restrict: 'A',
require: '?ngModel',
replace: true,
scope: true,
compile: function(tElement, tAttrs) {
  return function($scope) {
    var attrs = tElement[0].attributes;

    var attrsText = '';
    for (var i=0; i < attrs.length; i++) {
      var attr = attrs.item(i);
      if (attr.nodeName === "elem-as-attr") {
        continue;
      }
      attrsText += " " + attr.nodeName + "='" + attr.nodeValue + "'";        
    }

    var hasModel = $(tElement)[0].hasAttribute("ng-model");
    var innerHtml = $(tElement)[0].innerHTML;
    var html = '<' + tAttrs.elemAsAttr  + attrsText + '>' + innerHtml + '</' + tAttrs.elemAsAttr + '>';

    var e = hasModel ? $compile(html)($scope) : html;
    $(tElement).replaceWith(e);
  };
}
}
});
app.directive('elemAsAttr',function($compile){
返回{
限制:“A”,
要求:“?ngModel”,
替换:正确,
范围:正确,
编译:函数(远程通讯、tAttrs){
返回函数($scope){
var attrs=tElement[0]。属性;
var attrsText='';
对于(变量i=0;i
我不认为这是最佳的,但以我目前的代码知识,我很感谢我找到了这个解决方案。✌