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

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

1 Like
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 ạ

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()">
3 Likes

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

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?