简体   繁体   English

在开发人员模式下,是否在开发人员控制台中看到Angular 6单击绑定?

[英]See the Angular 6 click bindings in the developer console while in dev mode?

Assume I have a button with the following attributes: 假设我有一个具有以下属性的按钮:

<button>
    class="button"
    (click)="doStuff()"
    [ngClass]="{'stuff': selected}">
  Push me
 </button>

If I go to the console while running the app in development more, I only get a list of ng-reflect attributes that refer to my added attributes. 如果在开发环境中运行该应用程序的同时进入控制台,则只会得到一个ng-reflect属性列表,这些属性引用了我添加的属性。

Question is: why don't I also see the (click) binding i just added? 问题是:为什么我也看不到我刚刚添加的(单击)绑定?

Because your code is Typescript code, and when you want to look at it into your browser, it's Javascript code. 因为您的代码是Typescript代码,所以当您想在浏览器中查看它时,它就是Javascript代码。

When you write 当你写

<button>
    class="button"
    (click)="doStuff()"
    [ngClass]="{'stuff': selected}">
  Push me
</button>

This piece of HTML is actually translated in a string, that is used in the javascript code. 这段HTML实际上被翻译成一个字符串,该字符串在javascript代码中使用。

The compiler then search for (click) , and replace this code with ng-reflect="doStuff()" (this might not be true, but this is the idea). 然后,编译器搜索(click) ,并用ng-reflect="doStuff()"替换此代码(这可能不正确,但这是个主意)。

It then binds an event with button.addEventListener('click', () => {...}) , append the replaced string to the template, and your button then accepts click events. 然后, button.addEventListener('click', () => {...})一个事件与button.addEventListener('click', () => {...})绑定,将替换后的字符串附加到模板,然后您的按钮接受click事件。

This is an idea of how Angular works. 这是Angular的工作原理。 If you want to know exactly how it does that, you can look at their source code. 如果您想确切地知道它如何做到的,可以查看它们的源代码。

But bottom line is : (click) isn't valid JS on a HTML tag, it works because of the compiled code the framework provides when you build your application. 但最重要的是:( (click)不是HTML标记上的有效JS,它之所以起作用是因为框架在您构建应用程序时提供了已编译的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在有角度的应用程序中,通过chrome dev工具检查元素时,为什么看不到纯HTML? - In angular application, while inspecting an element via chrome dev tool, why do I not see pure html? 从开发者控制台填写 Angular 表单 - Fill Angular form from developer console 运行GWT开发人员模式时出错 - Error while running the GWT developer mode 从开发人员控制台在运行时修改角度对象 - Modifying angular objects at runtime from dev console 是什么导致我在Firefox开发人员控制台中看到的语法错误? - What is causing the syntax error I see in Firefox developer console? Web 开发人员如何查看用户控制台错误? - How can web developer see user console errors? 如何在Chrome开发者控制台中查看在DOJO中创建的单例对象? - How to see in chrome developer console a singleton object created in DOJO? jQuery .click函数不起作用,如何在chrome开发工具中查看? - jquery .click function not working, way to see in chrome dev tools? 使用开发者控制台在另一个Chrome标签中执行click()的Javascript - Javascript performing click() in another Chrome tab using developer console 仅在开发模式Angular 2中console.log - console.log only in development mode Angular 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM