Javascript 为什么';在Firefox中使用Typeahead更新我的ng型号?
在我建立的一个网站中,我有一个输入,下面有一个我使用的typeahead。它在Chrome、Opera和Safari中运行良好,但在Firefox中不起作用。问题似乎是,在Firefox中,当我单击typeahead建议时,模型没有更新 我的html如下所示: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
<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;
});
}