账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    angular2怎么往原生click事件中传递当前组件的属性?
    43
    0

    angular2中正常的点击事件是:(click)="selectClass(classItem)"这样的,classItem是当前组件中的属性,这样是没问题的,但是现在需要用到原生的点击事件如:onclick="routerTo()",这个时候要往这个函数中传递当前组件的属性该如何传递?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 凮殘あ淩度 普通会员 1楼

      在Angular 2中,如果你想在原生点击事件中传递当前组件的属性,你可以在点击事件处理器中使用$event对象来获取当前组件的属性。

      以下是一个简单的例子:

      ```typescript import { Component, OnInit } from '@angular/core';

      @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { title = 'Angular 2 Example'; constructor() {}

      ngOnInit() {}

      handleClick(event) { console.log(event.target.value); // 输出当前组件的属性值 } } ```

      在这个例子中,我们在handleClick方法中获取了点击事件的target对象,然后使用event.target.value来获取当前组件的属性值。

      请注意,你需要确保你的组件是可选的,并且在模板中包含一个按钮。如果没有包含,那么在点击事件处理器中无法获取到当前组件的属性。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部