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

jth*_*eis 1 keyboard-shortcuts angularjs angular-ui

我甚至无法简单地使用angular-ui启动和运行.我希望能够轻松检测按键,例如,在按下enter文本框后自动添加项目而无需按"添加"按钮.


这是我目前的尝试:

<!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']);
Run Code Online (Sandbox Code Playgroud)
function Ctrl($scope) {
  $scope.item = "";

  $scope.add = function () {
    $scope.item = "Item Added";
  }
}
Run Code Online (Sandbox Code Playgroud)

你可以在这里看到这个行为:http://jsfiddle.net/NbjZL/5/.请注意,在键入文本后单击按钮可以正常工作,但enter在键入文本后按下则不会.我已经阅读了我可以找到的文档,并查看了几个示例,但我确信我仍然缺少一些小东西.

nig*_*f0x 7

Angular ui无法找到角度应用程序.您需要做的就是在ng-app中指定应用名称以使其正常工作.

<html ng-app="myModule" xmlns="http://www.w3.org/1999/xhtml">
Run Code Online (Sandbox Code Playgroud)

检查js小提琴以查看代码是否正常工作