我正在尝试使用工具提示创建一个输入元素并将一个函数绑定到 enter keypress 事件。这些功能中的每一个都可以单独工作,但不能组合使用。这是标记:
<input type="text"
tooltip="tooltip text"
tooltip-placement="top"
tooltip-trigger="mouseover"
ng-model="currentTag"
ng-keypress="addTag($event)" />
和控制器相关的部分:
$scope.addTag = function($event) {
if($event.keyCode !== 13) return;
console.log($scope.currentTag); <---- currentTag is undefined here.
...
};
如果我省略工具提示指令,则代码可以正常工作。使 currentTag 未定义的 $scope 会发生什么?我该如何解决这个问题,以便上述工作?