AngularJS - $index, $event, $log
原文: https://thinkster.io/egghead/index-event-log
--------------------------------------------------------------
$index is a way to show which iteration of a loop you’re in. If we set up an ng-repeat to repeat over the letters in ‘somewords’, like so:
<div ng-app="app">
<div ng-repeat="item in 'somewords'.split('')">
{{$index + 1}}. {{item}}
</div>
</div>
We can see that we get a listing of all the characters in ‘somewords’ with the index next to it.
Now, let’s add an ng-click attribute to the div as “ev = $event” and a binding to ev.pageX. Let’s also set this div’s class to “button” since we’re going to be clicking on it
<div ng-app="app">
<div
class="button"
ng-repeat="item in 'somewords'.split('')"
ng-click="ev = $event"
>
{{$index + 1}}. {{item}}
{{ev.pageX}}
</div>
</div>
Now we can click on all of these buttons and whenever we click we get the extra number next to our index and character. This is the x value of where we’re clicking, and this shows that we can access the event that’s happening through $event.
If we want to log this event, we can do so by using $log. In order to use $log without setting up a controller, we can put it on the root scope of our application. We need to set up the run phase of our application and inject $rootScope and $log in order to expose $log to $rootScope
var app = angular.module("app", []);
app.run(function($rootScope, $log){
$rootScope.$log = $log;
});
Now we’re able to access the $log function anywhere within our app. (Note that you rarely want to put anything on the $rootScope as anything on the $rootScope will be available throughout the app.) Let’s change the ng-click attribute to “$log.debug($event)”
<div ng-app="app">
<div
class="button"
ng-repeat="item in 'somewords'.split('')"
ng-click="$log.debug($event)"
>
{{$index + 1}}. {{item}}
{{ev.pageX}}
</div>
</div>
Now we can open up our console and click on any of the buttons and we’ll see that the MouseEvent is being logged to the console. You can turn off the debug level of the logger in the config phase of the app by using $logProvider and calling debugEnabled and passing it false.
var app = angular.module("app", []);
app.config(function($logProvider){
$logProvider.debugEnabled(false);
});
app.run(function($rootScope, $log){
$rootScope.$log = $log;
});
Be sure to use proper logging levels in order for debugEnabled to work, as any info or warnings will still be logged
AngularJS - $index, $event, $log的更多相关文章
- log file switch (checkpoint incomplete) - 容易被误诊的event
本文转自 https://blogs.oracle.com/database4cn/log-file-switch-checkpoint-incomplete-%e5%ae%b9%e6%98%93%e ...
- jenkins发送带附件(logfile.log和index.html)的邮件配置
先进入到job里面,在Attachment中按照规矩添加文件就好了 此处是以workspace作为根目录的,logfile.log文件刚好就在根目录上,所以直接写上,多个文件的话用逗号分隔, 第二个文 ...
- python log
python的日志模块为logging,它可以将我们想要的信息输出保存到一个日志文件中. # cat log import logging logging.debug('This is debug m ...
- index index.html index.htm index.php
server { listen 80; server_name localhost; index index.html index.htm index.php;#前后顺序有关系,越在前优先级别越高 r ...
- git log用法【转】
转自:http://www.cnblogs.com/gbyukg/archive/2011/12/12/2285419.html PHP技术交流群 170855791 git log 查看提交记录,参 ...
- log file sync
Recently, our application system has updated one app. I receive a email of complain the db server ch ...
- [转][Angularjs]$http.post与$.post
本文转自:https://www.cnblogs.com/wolf-sun/p/6878868.html 摘要 在angularjs发送post请求的时候,确实很困惑,在传递json数据的时候,总会遇 ...
- MySQL启动报错Failed to open log (file 'D:\phpStudy\PHPTutorial\MySQL\data\mysql_bin.000045', errno 2)
MySQL报错 191105 9:39:07 [Note] Plugin 'FEDERATED' is disabled. 191105 9:39:07 InnoDB: The InnoDB memo ...
- 如何正确使用日志Log
title: 如何正确使用日志Log date: 2015-01-08 12:54:46 categories: [Python] tags: [Python,log] --- 文章首发地址:http ...
- UWP开发之Mvvmlight实践七:如何查找设备(Mobile模拟器、实体手机、PC)中应用的Log等文件
在开发中或者后期测试乃至最后交付使用的时候,如果应用出问题了我们一般的做法就是查看Log文件.上章也提到了查看Log文件,这章重点讲解下如何查看Log文件?如何找到我们需要的Packages安装包目录 ...
随机推荐
- webpack打包 css文件里面图片路径 替换位置
{ test: /\.css$/, use: ExtractTextPlugin.extract({ use: ['css-loader?minimize', 'autoprefixer-loader ...
- docker存储管理
Docker 镜像的元数据 repository元数据 repository在本地的持久化文件存放于/var/lib/docker/image/overlay2/repositories.json中 ...
- Asp.Net Core 入门(二)——Startup.cs做了什么
上篇介绍了Program.cs中Main做了什么,这篇我们来讨论下Startup.cs它又做了什么呢? 我们新建一个Asp.Net Core Mvc项目,先来开一下Startup的代码 public ...
- Proguard配置文件内容
-injars elec-bendao-1.2.jar-outjars elec-bendao-1.2-end.jar -libraryjars lib\charsets.jar-libraryjar ...
- No-10.高级变量类型
高级变量类型 目标 列表 元组 字典 字符串 公共方法 变量高级 知识点回顾 Python 中数据类型可以分为 数字型 和 非数字型 数字型 整型 (int) 浮点型(float) 布尔型(bool) ...
- JavaScript递归简单实现个对象深拷贝
JavaScript中对象的深拷贝来说一直都算比较恶心 毕竟没有什么api能直接全拷贝了 得自己便利写 最近在项目中需要深拷贝 自己简单封了个方法 话不多说 直接上码 <!DOCTYPE ht ...
- 第三章:systemverilog文本值和数据类型
1.增强的文本值 2.改进的`define文本替换 3.时间值 4.新的变量类型 5.有符号和无符号类型 6.静态和动态变量(***) 7.类型转换 8.常数 增强的文本值(文本赋值增强) 主要是:位 ...
- windows下安装rabbitmq以及php扩展amqp
先安装RabbitMQ 安装Erlang 下载地址http://www.erlang.org/downloads 我选的是64位 这个根据自己情况下载,双击安装之 安装RabbitMQ 下载地址ht ...
- c#如何判断textbox中输入的数据是datatime型的
()你好,标准的方法是用一个验证控件:RangeValidator,把type设为DateTime,最大值设为'3000-1-1'或者别的,最小值最好设为'1900-1-1'. ()程序里面自己验证: ...
- Idea中配置svn时报 Can't use Subversion command line client: svn.Errors found while svn working copies detection.
https://www.cnblogs.com/wqh17/p/6881483.html