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
Javascript 为什么';在Firefox中使用Typeahead更新我的ng型号?_Javascript_Angularjs_Firefox_Typeahead.js_Angular Ngmodel - Fatal编程技术网

Javascript 为什么';在Firefox中使用Typeahead更新我的ng型号?

Javascript 为什么';在Firefox中使用Typeahead更新我的ng型号?,javascript,angularjs,firefox,typeahead.js,angular-ngmodel,Javascript,Angularjs,Firefox,Typeahead.js,Angular Ngmodel,在我建立的一个网站中,我有一个输入,下面有一个我使用的typeahead。它在Chrome、Opera和Safari中运行良好,但在Firefox中不起作用。问题似乎是,在Firefox中,当我单击typeahead建议时,模型没有更新 我的html如下所示: <input class="typeahead" sf-typeahead type="text" datasets="userDataset" ng-model="searchUser" > <button ng-cl

在我建立的一个网站中,我有一个输入,下面有一个我使用的typeahead。它在Chrome、Opera和Safari中运行良好,但在Firefox中不起作用。问题似乎是,在Firefox中,当我单击typeahead建议时,模型没有更新

我的html如下所示:

<input class="typeahead" sf-typeahead type="text" datasets="userDataset" ng-model="searchUser" >
<button ng-click="sendToUser(searchUser.id)" class="btn">Send</button>
在Chrome、Opera和Safari中,它会记录
用户ID的int,但在Firefox中,它只记录
未定义的

我做了一个搜索来显示我的意思(搜索“一”或“两”)

它可以在Chrome、Opera和Safari中使用,但在Firefox中,它会在控制台中显示
undefined
。更奇怪的是,它第一次只显示
未定义的
。如果你第二次选择某个东西,它会起作用


有人知道为什么这在Firefox中不起作用吗?最重要的是,我如何解决它?欢迎所有提示

这是一个有趣的困境

  • 选择对象后,TypeAhead
    ng model
    值设置为对象

  • 在运行摘要循环的任何事件(如单击)发生时,框架强制执行
    ng model
    绑定,为模型值分配一个绑定到输入的字符串

  • FireFox,与Chrome不同,它似乎强化了这种行为Chrome输入可能允许对象值设置(只是猜测)


解决方法是更改输出绑定:

<input class="typeahead" sf-typeahead type="text"  datasets="userDataset" 
outputval="searchUser" ng-model="a" options="exampleOptions">

试试我的

我试过你的Chrome和FF。两者似乎都很有效。有时,在FF中的TypeAhead外单击可“取消选择”模型。因此,模型被正确绑定,但随后被解除绑定。当我点击“发送”按钮并做出选择时,这个错误不会再次出现,直到我做出另一个选择。@DaveAlperovich-好的,那么你知道我们如何在使用Firefox时保持模型处于选中状态吗?还没有。非常奇怪的行为。模型解析器正在启动,这意味着,不知何故,click事件启动了一个摘要循环(已经很奇怪了),并使用当前索引作为值。两者都很奇怪。我还找不到与此对应的绑定事件。是的,我看到发生了什么。
ng模型
绑定与对象分配冲突。选择后,您将“searchUser”设置为对象的值。但是,在文摘周期运行的那一刻,“searchUser”就变成了绑定到输入的字符串。此字符串没有子id。
<input class="typeahead" sf-typeahead type="text"  datasets="userDataset" 
outputval="searchUser" ng-model="a" options="exampleOptions">
    function updateScope (object, suggestion, dataset) {
      scope.$apply(function () {
        var newViewValue = (angular.isDefined(scope.suggestionKey)) ?
            suggestion[scope.suggestionKey] : suggestion;
        console.log(newViewValue);    
        //ngModel.$setViewValue(newViewValue);
        scope.outputval = newViewValue;
      });
    }