Angular-UI ui-keypress无法正常工作

Angular-UI ui-keypress无法正常工作

问题描述:

即使简单地使用angular-ui启动并运行,我也遇到了麻烦。我希望能够轻松检测按键,例如,在文本框中按enter后自动添加项目,而无需按下添加按钮。Angular-UI ui-keypress无法正常工作


这是我当前的尝试:

<!DOCTYPE html> 
<html ng-app xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Main</title> 
    <link rel="stylesheet", href="http://angular-ui.github.com/angular-ui/build/angular-ui.css" /> 
</head> 
<body ng-controller="Ctrl"> 
    <button ng-click="add()">Add</button> 
    <input type="text" ui-keypress="{enter: 'add()'}" /> 
    {{item}} 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"> </script> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script> 
    <script src="http://angular-ui.github.com/angular-ui/build/angular-ui.js"></script> 
    <script src="main.js"></script> 
</body> 
</html> 

var myApp = angular.module('myApp', ['ui.directives']); 

function Ctrl($scope) { 
    $scope.item = ""; 

    $scope.add = function() { 
    $scope.item = "Item Added"; 
    } 
} 

您可以在这里看到的行为:http://jsfiddle.net/NbjZL/5/。请注意,在输入文字后单击按钮,但在输入文字后按enter则不行。我已经阅读了我可以找到的文档并查看了几个示例,但我确定我仍然错过了一些小东西。

Angular ui无法找到角度应用程序。您只需在ng-app中指定应用程序名称即可运行。

<html ng-app="myModule" xmlns="http://www.w3.org/1999/xhtml"> 

检查js fiddle看到代码工作

+0

唉!我不知道那个小小的属性最终会咬我。先生,很多荣誉! – jtheis