如何在Angularjs中使用firefox中的事件,因为它说事件是未定义的?

时间:2016-07-26 22:05:16

标签: javascript angularjs

这是我的Angular功能,当您双击所需字段,更改数据并按Enter键时,它基本上会更新数据:

 $scope.contentEdit = function(data, event) {
    console.log("event", event); //this function triggers when the user edit student's data from the table and updates new data to local storage.
    for (var i = 0; i < $scope.students.length; i++) {
        if ($scope.students[i].studentName == data) {
            $scope.students[i].studentName = event.target.innerText;
        } else if ($scope.students[i].Marks == data) {
            $scope.students[i].Marks = parseInt(event.target.innerText);
            $scope.students[i].pass = ($scope.students[i].Marks > 65) ? true : false;
        }
    }
    localStorage.setItem('studentsList', JSON.stringify($scope.students));
    event.target.contentEditable = event.target.contentEditable == "false" ? "true" : "false";
};

我已经从我的html传递$ event作为contentEdit(student.studentName,$ event),但它仍然无法正常工作。 每当我双击该字段时,它就会在控制台上成功记录双击事件,但只要我按下Enter键,它就会抛出并且错误该事件未定义。

1 个答案:

答案 0 :(得分:0)

您使用ng-dblclick指令吗?如果是,我认为你有语法错误。

&#13;
&#13;
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.contentEdit = function(data, event) {
        console.log(event);
    };
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
    <div ng-dblclick="contentEdit(1, $event)">dblclick me to see the console</div>
</div>
&#13;
&#13;
&#13;