简体   繁体   中英

Access DOM element “onSubmit” button click using Jquery in AngularJS 2.0

How can i access Jquery on button click event of angularjs 2.0? Check my code, that I've done.

 import {Component, View, ElementRef, OnInit} from 'angular2/core'; import {Router} from 'angular2/router'; declare var jQuery:any; @Component({ templateUrl: 'login.html' }) export class LoginComponent implements OnInit { elementRef: ElementRef; constructor(elementRef: ElementRef) { this.elementRef = elementRef; } onSignup() { jQuery(this.elementRef.nativeElement).find('#register-box').css({height:"0", opecity:"0"}); jQuery(this.elementRef.nativeElement).find('#success-box').css({height:"100%", opecity:"1"}); } } 

but this gives error like, TypeError: Cannot read property 'nativeElement' of undefined

Resolved by below code,

 onSignup() { var _this = this.model; if(Factory.signup(this.model).then(function(response) {if(response['status']){_this._id = response['result']; return true;}else{return false;};})) { jQuery(this.elementRef.nativeElement).find('#success-box').css({height: "100%",opacity: "1"}); jQuery(this.elementRef.nativeElement).find('#register-box').css({height: "0",opacity: "0"}); } } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM