Reputation: 21
I am totally new to Angular 2 and started learning it 2 days back. I have used 'templateUrl' property in one of my component so that clicking on some button creates tab view , code of which is written in some other html file named 'tabs.html'.
Now in this new html file, I am calling a function 'openTab' on click of a button. This function is written in same file - 'tabs.html'. While executing the app, system is unable to find the function 'openTab' even though it is in same file.
However, if I move this function to index.html, which is said to be a welcome file for angular 2 , system is able to find the function.
Why is this happening?
Should I write all the global functions in index.html?
Upvotes: 1
Views: 11860
Reputation: 690
index.html is the default page. When you create a new project, you can find this in index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>LPV</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root>Loading...</app-root>
</body>
</html>
The <app-root>
tag is the name of the selector of the default app.component.ts file, so this is the app component which be called.
You can change the default page to show by replacing <app-root>
by the selector of your component in the index.html, or you can create a router to redirect to your component, I advise you to follow this tutorial : https://angular.io/docs/ts/latest/tutorial/toh-pt5.html
Upvotes: 1