01/10/2018, 13:43

Làm sao để chạy typescript khi load trang?

Làm sao để chạy typescript khi load trang, lúc mới bắt đầu vào trang?
Xin cảm ơn

Dark.Hades viết 15:55 ngày 01/10/2018

Bạn phải compile/translate nó sang javascript thuần rồi nó chạy như bình thường thôi.

Bảo Ngọc viết 15:51 ngày 01/10/2018
import { Component, OnInit } from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";

import {FadeInLeft} from "../../shared/animations/fade-in-left.decorator";
import { and } from '@angular/router/src/utils/collection';

@FadeInLeft()
@Component({
  selector: 'sa-expoverview',
  templateUrl: './overview.component.html',
  styleUrls:['./overview.component.css'],
})

export class expOverviewComponent implements OnInit {
ngOnInit(){}
}

File typescript bình thường của mình như này, mình biết cách gọi function khi ấn vào element rồi, nhưng không biết cách nào để chạy 1 function khi load trang ạ

Dark.Hades viết 15:57 ngày 01/10/2018

Mình không dùng typescript cũng như chưa có nhiều kinh nghiệm về ES5-6.
Ở đây bạn có thể dùng trực tiếp trick là

File xxx.ts
import xxx from zzz;
...

window.callOnLoad = () => {
  alert(1);
}

Ở body:

<body onload="callOnLoad()">
Bảo Ngọc viết 15:49 ngày 01/10/2018

Cảm ơn bạn nhiều!!!

Bài liên quan
0