博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
angularjs教程_AngularJS活动教程
阅读量:2534 次
发布时间:2019-05-11

本文共 3239 字,大约阅读时间需要 10 分钟。

angularjs教程

As a web developer, we will have to deal with different DOM events like key press, mouse moves, mouse clicks and other change events.  In this tutorial, we will look into the AngularJS Directives for handling these events with suitable examples.

作为Web开发人员,我们将不得不处理不同的DOM事件,例如按键,鼠标移动,鼠标单击和其他更改事件。 在本教程中,我们将通过适当的示例介绍用于处理这些事件的AngularJS指令。

内容: (Contents:)

  • Introduction to AngularJS Event Listener Directives

    AngularJS事件侦听器指令简介
  • AngularJS events example

    AngularJS事件示例

AngularJS事件侦听器指令简介 (Introduction to AngularJS Event Listener Directives)

The following list shows the available AngularJS event listener directives for DOM events.

以下列表显示了DOM事件的可用AngularJS事件侦听器指令。

  • ng-click

    ng-点击
  • ng-dblclick

    ng-dblclick
  • ng-keydown

    ng-keydown
  • ng-keypress

    ng键
  • ng-keyup

    ng-keyup
  • ng-mousedown

    ng-mousedown
  • ng-mouseenter

    ng-mouseenter
  • ng-mouseleave

    ng-mouseleave
  • ng-change

    ng-change

用法 (Usage)

We can use above AngularJS event listener directives as an attribute of HTML element as shown below.

我们可以将上面的AngularJS事件侦听器指令用作HTML元素的属性,如下所示。

........

Here expression is evaluated on triggering each event.

这里, 表达式是在触发每个事件时进行评估的。

AngularJS事件示例 (AngularJS Events Example)

The following example demonstrates the angularJS events. Directives like ngClick, ngFocus etc expose a $event object within the scope of that expression. The object is an instance of a jQuery Event Object when jQuery is present or a similar jqLite object. The event object is also available for key events and can be used to get keyCode, altKey etc. values.

以下示例演示了angularJS事件。 诸如ngClickngFocus等指令在该表达式的范围内公开了$event对象。 当存在jQuery或类似的jqLite对象时,该对象是jQuery事件对象的实例。 事件对象也可用于键事件,并可用于获取keyCodealtKey等值。

index.html

index.html

	
ngClick Directive
{
{ clicked }}
ngDblclick Directive
{
{ count }}
ngMousedown and ngMouseup Directive
ngMouseenter and ngMouseleave Directives
ngMousemove Directive
Moved {
{moveCnt}} times.
ngkeyup Directive Type something :
key up count: {
{keyupcount}}
ngkeydown Directive Type something :
event keyCode: {
{ event.keyCode }}
ngChange Directive Checked :
{
{checked}}

The controller is created in the following file. You can see the use of $event object.

在以下文件中创建控制器。 您可以看到$event对象的使用。

app.js

app.js

var app = angular.module('myApp', []);app.controller('myCtrl', function($scope) {    $scope.onClick = function(event){          $scope.clicked = "Clicked On X: "+event.clientX +" and Y: "+event.clientY;    };});

The following CSS styling is used in the example.

本示例中使用以下CSS样式。

mystyle.css

mystyle.css

.btn1 {  color: #FFF;  background-color: #900;  font-weight: bold;  font-size : 20px;}.btn2 {  color: #FFF;  background-color: green;  font-weight: bold;  font-size : 20px;}.btn3 {  color: #FFF;  background-color: blue;  font-weight: bold;  font-size : 20px;}.txt {   border: 1px solid red;}.red {  background-color: red;}.green {  background-color: green;}

Now you can play with following output.

现在您可以播放以下输出。

That’s all for now and we will see more angularJS features in upcoming tutorials.

到此为止,我们将在接下来的教程中看到更多angularJS功能。

翻译自:

angularjs教程

转载地址:http://ntlzd.baihongyu.com/

你可能感兴趣的文章
iOS语言中的KVO机制
查看>>
excel第一次打开报错 向程序发送命令时出错 多种解决办法含终极解决方法
查看>>
响应式web设计之CSS3 Media Queries
查看>>
实验三
查看>>
机器码和字节码
查看>>
环形菜单的实现
查看>>
【解决Chrome浏览器和IE浏览器上传附件兼容的问题 -- Chrome关闭flash后,uploadify插件不可用的解决办法】...
查看>>
34 帧动画
查看>>
二次剩余及欧拉准则
查看>>
Centos 7 Mysql 最大连接数超了问题解决
查看>>
thymeleaf 自定义标签
查看>>
关于WordCount的作业
查看>>
C6748和音频ADC连接时候的TDM以及I2S格式问题
查看>>
UIView的layoutSubviews,initWithFrame,initWithCoder方法
查看>>
STM32+IAP方案 实现网络升级应用固件
查看>>
用74HC165读8个按键状态
查看>>
jpg转bmp(使用libjpeg)
查看>>
linear-gradient常用实现效果
查看>>
sql语言的一大类 DML 数据的操纵语言
查看>>
VMware黑屏解决方法
查看>>