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安装包目录 ...
随机推荐
- 1.入手树莓派之linux环境搭建
最近刚刚买了一款 树莓派3代B型 raspberrypi 板载蓝牙和WIFI 英国版本,没玩过,觉得很好奇,生怕记性不好哈,把自己玩的过程记录一下,以备不时之需: 需要材料: 1) 树莓派: 2)sd ...
- saltstack install on centos7
saltstack offical website reference blog summary install virtualbox yum install VirtualBox-5.2 insta ...
- IOS学习笔记3—Objective C—简单的内存管理
今天简述一下简单的内存管理,在IOS5.0以后Apple增加了ARC机制(Automatic Reference Counting),给开发人员带来了不少的方便,但是为了能更好的理解IOS内存管理机制 ...
- POI导出,开发中经常会遇到数据导出这样的问题,下面是我在开发中采用的解决方法,大家可以参考,具体的实现害的结合你自身的业务逻辑
@RequestMapping(value = "/drawPayFailExport",method = RequestMethod.GET,produces = "a ...
- 201621123079《java程序设计》第六周作业总结
作业06-接口.内部类 1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结. 2. 书面作业 1. c ...
- 条款36:绝不重新定义继承而来的non-virtual函数(Never redefine an inherited non-virtual function)
NOTE: 1.绝对不要重新定义继承而来的non-virtual函数.
- DEVExpress中BarItem的使用2
没有验证LookUpEdit与ComBox的区别. 没有验证ZoomTrackBarControl的使用方法. SparkLine看着也蛮有趣,需要绑定数据源控件的均没有验证. 前一节介绍的BarIt ...
- DEV Express中Bar Manager的使用
未排版 在barManager中可以添加多种元素,如皮肤按钮,复选框等,但是下拉菜单却给出了多个冗余的控件. 遗留问题:怎么设置Bar为大图标,查找是否存在Ribbon控件. Bar 1, ...
- Photoshop保存的各种格式详解
1.PSD(*.PSD) PSD格式是Adobe Photoshop软件自身的格式,这种格式可以存储Photoshop中所有的图层,通道.参考线.注解和颜色模式等信息.在保存图像时,若图像中包含有层, ...
- 会跳舞的树(只用HTML+CSS)(转)
效果如下. 共有1022个<div>元素. See the Pen wKvrMa by moyu (@MoYu1991) on CodePen.