Home » Javascript » read typescript class member inside javascript function

read typescript class member inside javascript function

Posted by: admin October 29, 2018 Leave a comment

Questions:

This is my code :

    export class CustomToast implements OnInit {
            toastTypeGroup: string;
            message: string;
            title: string; 
            showDuration= "300";

            constructor(_toastTypeGroup: string, _message:string, _title: string ){
                this.toastTypeGroup = _toastTypeGroup;
                this.message = _message;
                this.title =  _title;
            }

            ngOnInit() {
                **//this is the solution** 
                **var _this = this;**
                console.log(this.showDuration);
                var ToastrDemo = function () {
                    var toastr: any = (<any>window).toastr;
                    var k, m = -1, f = 0;

                    var t = function () {
                        var t, o,
                            //toastTypeGroup
                            e = this.toastTypeGroup,
                            //message
                            n = this.message,
                            //title
                            a = this.title,
                            //showDuration
                            i = this.showDuration,
                    };

                    return { init: function () { t() } }
                }();jQuery(document).ready(function () { ToastrDemo.init() });

            }



        }

My problem is that I want to read members values from my class called CustomToast inside my JavaScript function called var t = function () {…}.

I can’t get typescript class member value inside a JavaScript Function.
e.g “toastTypeGroup” member is not accessible iside my fucntion
This is the big problem.

Thanks in advance.

Answers: