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安装包目录 ...
随机推荐
- 关于sigleton模式
单例模式的要点有三个:一是某个类只能有一个实例:二是它必须自行创建这个实例:三是它必须自行向整个系统提供这个实例. 从具体实现角度来说,就是以下三点:一是单例模式的类只提供私有的构造函数,二是类定义中 ...
- No-2.常用 Linux 命令的基本使用
常用 Linux 命令的基本使用 01. 学习 Linux 终端命令的原因 Linux 刚面世时并没有图形界面,所有的操作全靠命令完成,如 磁盘操作.文件存取.目录操作.进程管理.文件权限 设定等 在 ...
- Ubuntu18.04 NVIDIA显卡驱动 安装大全
离线安装NVIDIA显卡驱动 费了一天的劲,走了好多的坑,最主要的原因是gcc版本的问题,一定要用最新版本的gcc!!! 1)官网下载显卡驱动 2)apt 下载gcc包及其依赖包,可用apt-cach ...
- linux 搜索文本
find -type f -name '*.php'|xargs grep '127.0.0.1' 搜索所有.php 内容 127.0.0.1 转自:http://www.cnblogs.com/w ...
- Tunnelier使用说明
Tunnelier与MyEnTunnel类似,但是功能更加强大.MyEnTunnel小巧易用,如何使用MyEnTunnel可以参考 MyEnTunnel使用说明 这里列下Tunnelier的优点: 1 ...
- OI Journal
佛系更新,哪天想起来就写点. 10.11 班主任硬灌的鸡汤真香 qtmd,简直就是硬扯,说怎么怎么着说不定就能多拿一分两分,一分两分就能割掉好多人 ......螺旋懵圈状,我表示硬憋着不笑 HIAHI ...
- c++_凑算式(最新方法)
凑算式 B DEFA + --- + ------- = 10 C GHI (如果显示有问题,可以参见[图1.jpg]) 这个算式中A~I代表1~9的数字,不同的字母代表不同的数字. 比如:6+8/3 ...
- Java:post请求
文章来源:https://www.cnblogs.com/hello-tl/p/9140870.html 0.post请求返回json import java.io.BufferedInputStre ...
- JAVA:windows myeclipse jdk tomcat maven 完美搭建
文章来源:http://www.cnblogs.com/hello-tl/p/8305027.html 0.下载所需安装包 jdk-7u71-windows-x64.exe 链接:http://p ...
- LeetCode(18)4Sum
题目 Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = ...