why is not a known element with out body tag
I am new to this angular 6. This may be stupid to ask but i want to make my concept clear. Below is the code my of appComponent typescript
import { Component, OnInit, Inject } from '@angular/core';
import {ToastrService} from './services/toastr.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ,
providers:[ToastrService]
})
export class AppComponent {
}
when i put <app-root>
in the index.html in the following format. it works perfectly fine.
<html>
<body>
<app-root></app-root>
</body>
</html>
but when i remove the html and body tags it just give me an error given below.
main.ts:12 Error: The selector "app-root" did not match any elements
at DefaultDomRenderer2.push../node_modules/@angular/platform-browser/fesm5/platform-browser.js.DefaultDomRenderer2.selectRootElement (platform-browser.js:1073)
at BaseAnimationRenderer.push../node_modules/@angular/platform-browser/fesm5/animations.js.BaseAnimationRenderer.selectRootElement (animations.js:229)
at DebugRenderer2.push../node_modules/@angular/core/fesm5/core.js.DebugRenderer2.selectRootElement (core.js:20837)
at createElement (core.js:17499)
at createViewNodes (core.js:19737)
at createRootView (core.js:19690)
at callWithDebugContext (core.js:20722)
at Object.debugCreateRootView [as createRootView] (core.js:20208)
at ComponentFactory_.push../node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create (core.js:18029)
at ComponentFactoryBoundToModule.push../node_modules/@angular/core/fesm5/core.js.ComponentFactoryBoundToModule.create
So my question is.. Do i have to write <app-root>
alway in html or body tag? or is there any other way to write <app-root>
with out writing in html or body tag?
Thanks
angular angular5 angular6
add a comment |
I am new to this angular 6. This may be stupid to ask but i want to make my concept clear. Below is the code my of appComponent typescript
import { Component, OnInit, Inject } from '@angular/core';
import {ToastrService} from './services/toastr.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ,
providers:[ToastrService]
})
export class AppComponent {
}
when i put <app-root>
in the index.html in the following format. it works perfectly fine.
<html>
<body>
<app-root></app-root>
</body>
</html>
but when i remove the html and body tags it just give me an error given below.
main.ts:12 Error: The selector "app-root" did not match any elements
at DefaultDomRenderer2.push../node_modules/@angular/platform-browser/fesm5/platform-browser.js.DefaultDomRenderer2.selectRootElement (platform-browser.js:1073)
at BaseAnimationRenderer.push../node_modules/@angular/platform-browser/fesm5/animations.js.BaseAnimationRenderer.selectRootElement (animations.js:229)
at DebugRenderer2.push../node_modules/@angular/core/fesm5/core.js.DebugRenderer2.selectRootElement (core.js:20837)
at createElement (core.js:17499)
at createViewNodes (core.js:19737)
at createRootView (core.js:19690)
at callWithDebugContext (core.js:20722)
at Object.debugCreateRootView [as createRootView] (core.js:20208)
at ComponentFactory_.push../node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create (core.js:18029)
at ComponentFactoryBoundToModule.push../node_modules/@angular/core/fesm5/core.js.ComponentFactoryBoundToModule.create
So my question is.. Do i have to write <app-root>
alway in html or body tag? or is there any other way to write <app-root>
with out writing in html or body tag?
Thanks
angular angular5 angular6
1
This would be an interesting opportunity for you to follow the stack trace and dive into the Angular source code to see how it is finding the root element.
– Ben Steward
Nov 22 at 19:39
Yeah dude, and I’m saying the source code may answer his question and reveal some interesting tidbits about how else he might do whatever he is trying to do.
– Ben Steward
Nov 22 at 20:03
Possible duplicate of Angular2 - Error: The selector "app-root" did not match any elements
– Mahi
Nov 22 at 20:13
add a comment |
I am new to this angular 6. This may be stupid to ask but i want to make my concept clear. Below is the code my of appComponent typescript
import { Component, OnInit, Inject } from '@angular/core';
import {ToastrService} from './services/toastr.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ,
providers:[ToastrService]
})
export class AppComponent {
}
when i put <app-root>
in the index.html in the following format. it works perfectly fine.
<html>
<body>
<app-root></app-root>
</body>
</html>
but when i remove the html and body tags it just give me an error given below.
main.ts:12 Error: The selector "app-root" did not match any elements
at DefaultDomRenderer2.push../node_modules/@angular/platform-browser/fesm5/platform-browser.js.DefaultDomRenderer2.selectRootElement (platform-browser.js:1073)
at BaseAnimationRenderer.push../node_modules/@angular/platform-browser/fesm5/animations.js.BaseAnimationRenderer.selectRootElement (animations.js:229)
at DebugRenderer2.push../node_modules/@angular/core/fesm5/core.js.DebugRenderer2.selectRootElement (core.js:20837)
at createElement (core.js:17499)
at createViewNodes (core.js:19737)
at createRootView (core.js:19690)
at callWithDebugContext (core.js:20722)
at Object.debugCreateRootView [as createRootView] (core.js:20208)
at ComponentFactory_.push../node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create (core.js:18029)
at ComponentFactoryBoundToModule.push../node_modules/@angular/core/fesm5/core.js.ComponentFactoryBoundToModule.create
So my question is.. Do i have to write <app-root>
alway in html or body tag? or is there any other way to write <app-root>
with out writing in html or body tag?
Thanks
angular angular5 angular6
I am new to this angular 6. This may be stupid to ask but i want to make my concept clear. Below is the code my of appComponent typescript
import { Component, OnInit, Inject } from '@angular/core';
import {ToastrService} from './services/toastr.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ,
providers:[ToastrService]
})
export class AppComponent {
}
when i put <app-root>
in the index.html in the following format. it works perfectly fine.
<html>
<body>
<app-root></app-root>
</body>
</html>
but when i remove the html and body tags it just give me an error given below.
main.ts:12 Error: The selector "app-root" did not match any elements
at DefaultDomRenderer2.push../node_modules/@angular/platform-browser/fesm5/platform-browser.js.DefaultDomRenderer2.selectRootElement (platform-browser.js:1073)
at BaseAnimationRenderer.push../node_modules/@angular/platform-browser/fesm5/animations.js.BaseAnimationRenderer.selectRootElement (animations.js:229)
at DebugRenderer2.push../node_modules/@angular/core/fesm5/core.js.DebugRenderer2.selectRootElement (core.js:20837)
at createElement (core.js:17499)
at createViewNodes (core.js:19737)
at createRootView (core.js:19690)
at callWithDebugContext (core.js:20722)
at Object.debugCreateRootView [as createRootView] (core.js:20208)
at ComponentFactory_.push../node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create (core.js:18029)
at ComponentFactoryBoundToModule.push../node_modules/@angular/core/fesm5/core.js.ComponentFactoryBoundToModule.create
So my question is.. Do i have to write <app-root>
alway in html or body tag? or is there any other way to write <app-root>
with out writing in html or body tag?
Thanks
angular angular5 angular6
angular angular5 angular6
edited Nov 22 at 19:13
asked Nov 22 at 19:06
zaid khan
537
537
1
This would be an interesting opportunity for you to follow the stack trace and dive into the Angular source code to see how it is finding the root element.
– Ben Steward
Nov 22 at 19:39
Yeah dude, and I’m saying the source code may answer his question and reveal some interesting tidbits about how else he might do whatever he is trying to do.
– Ben Steward
Nov 22 at 20:03
Possible duplicate of Angular2 - Error: The selector "app-root" did not match any elements
– Mahi
Nov 22 at 20:13
add a comment |
1
This would be an interesting opportunity for you to follow the stack trace and dive into the Angular source code to see how it is finding the root element.
– Ben Steward
Nov 22 at 19:39
Yeah dude, and I’m saying the source code may answer his question and reveal some interesting tidbits about how else he might do whatever he is trying to do.
– Ben Steward
Nov 22 at 20:03
Possible duplicate of Angular2 - Error: The selector "app-root" did not match any elements
– Mahi
Nov 22 at 20:13
1
1
This would be an interesting opportunity for you to follow the stack trace and dive into the Angular source code to see how it is finding the root element.
– Ben Steward
Nov 22 at 19:39
This would be an interesting opportunity for you to follow the stack trace and dive into the Angular source code to see how it is finding the root element.
– Ben Steward
Nov 22 at 19:39
Yeah dude, and I’m saying the source code may answer his question and reveal some interesting tidbits about how else he might do whatever he is trying to do.
– Ben Steward
Nov 22 at 20:03
Yeah dude, and I’m saying the source code may answer his question and reveal some interesting tidbits about how else he might do whatever he is trying to do.
– Ben Steward
Nov 22 at 20:03
Possible duplicate of Angular2 - Error: The selector "app-root" did not match any elements
– Mahi
Nov 22 at 20:13
Possible duplicate of Angular2 - Error: The selector "app-root" did not match any elements
– Mahi
Nov 22 at 20:13
add a comment |
1 Answer
1
active
oldest
votes
Yes, <app-root>
always in html or body tag as long as you want to display your <app-root>
module.
Angular2+
architecture is modular i.e. it has divided view into multiple reusable components where
template(.html) is view
.ts is considered to be controller for business logic.
So, here is parent module which contains app.module.ts and its corresponding .ts,.html,.css,.spec
file.
Index.html is the first page which loads as simple as you have worked in html pages which consist of a <html>,<head>,<body>
tags.
index.html
The page which first loads and contain <html>,<head>,<body> tags.
index.html
<html>
<head>
<script></script>
<link></link>
</head>
<body>
Hello world.
<app-root></app-root> <--- where whole module loads-- Root selctor
</body>
</html>
app.component.ts
@Component({
selector: 'app-root'
})
app.module.ts
bootstrap: [AppComponent] <-- appComponent is bootstrapped(root component)
please have a look at the below example. He is not using any html tag in index.html stackblitz.com/edit/angular-multi-layout-example?file=main.ts
– zaid khan
Nov 22 at 19:29
Read Stackblitz docs- stackblitz.com/docs
– Mahi
Nov 22 at 19:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436869%2fwhy-app-root-is-not-a-known-element-with-out-body-tag%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yes, <app-root>
always in html or body tag as long as you want to display your <app-root>
module.
Angular2+
architecture is modular i.e. it has divided view into multiple reusable components where
template(.html) is view
.ts is considered to be controller for business logic.
So, here is parent module which contains app.module.ts and its corresponding .ts,.html,.css,.spec
file.
Index.html is the first page which loads as simple as you have worked in html pages which consist of a <html>,<head>,<body>
tags.
index.html
The page which first loads and contain <html>,<head>,<body> tags.
index.html
<html>
<head>
<script></script>
<link></link>
</head>
<body>
Hello world.
<app-root></app-root> <--- where whole module loads-- Root selctor
</body>
</html>
app.component.ts
@Component({
selector: 'app-root'
})
app.module.ts
bootstrap: [AppComponent] <-- appComponent is bootstrapped(root component)
please have a look at the below example. He is not using any html tag in index.html stackblitz.com/edit/angular-multi-layout-example?file=main.ts
– zaid khan
Nov 22 at 19:29
Read Stackblitz docs- stackblitz.com/docs
– Mahi
Nov 22 at 19:46
add a comment |
Yes, <app-root>
always in html or body tag as long as you want to display your <app-root>
module.
Angular2+
architecture is modular i.e. it has divided view into multiple reusable components where
template(.html) is view
.ts is considered to be controller for business logic.
So, here is parent module which contains app.module.ts and its corresponding .ts,.html,.css,.spec
file.
Index.html is the first page which loads as simple as you have worked in html pages which consist of a <html>,<head>,<body>
tags.
index.html
The page which first loads and contain <html>,<head>,<body> tags.
index.html
<html>
<head>
<script></script>
<link></link>
</head>
<body>
Hello world.
<app-root></app-root> <--- where whole module loads-- Root selctor
</body>
</html>
app.component.ts
@Component({
selector: 'app-root'
})
app.module.ts
bootstrap: [AppComponent] <-- appComponent is bootstrapped(root component)
please have a look at the below example. He is not using any html tag in index.html stackblitz.com/edit/angular-multi-layout-example?file=main.ts
– zaid khan
Nov 22 at 19:29
Read Stackblitz docs- stackblitz.com/docs
– Mahi
Nov 22 at 19:46
add a comment |
Yes, <app-root>
always in html or body tag as long as you want to display your <app-root>
module.
Angular2+
architecture is modular i.e. it has divided view into multiple reusable components where
template(.html) is view
.ts is considered to be controller for business logic.
So, here is parent module which contains app.module.ts and its corresponding .ts,.html,.css,.spec
file.
Index.html is the first page which loads as simple as you have worked in html pages which consist of a <html>,<head>,<body>
tags.
index.html
The page which first loads and contain <html>,<head>,<body> tags.
index.html
<html>
<head>
<script></script>
<link></link>
</head>
<body>
Hello world.
<app-root></app-root> <--- where whole module loads-- Root selctor
</body>
</html>
app.component.ts
@Component({
selector: 'app-root'
})
app.module.ts
bootstrap: [AppComponent] <-- appComponent is bootstrapped(root component)
Yes, <app-root>
always in html or body tag as long as you want to display your <app-root>
module.
Angular2+
architecture is modular i.e. it has divided view into multiple reusable components where
template(.html) is view
.ts is considered to be controller for business logic.
So, here is parent module which contains app.module.ts and its corresponding .ts,.html,.css,.spec
file.
Index.html is the first page which loads as simple as you have worked in html pages which consist of a <html>,<head>,<body>
tags.
index.html
The page which first loads and contain <html>,<head>,<body> tags.
index.html
<html>
<head>
<script></script>
<link></link>
</head>
<body>
Hello world.
<app-root></app-root> <--- where whole module loads-- Root selctor
</body>
</html>
app.component.ts
@Component({
selector: 'app-root'
})
app.module.ts
bootstrap: [AppComponent] <-- appComponent is bootstrapped(root component)
edited Nov 22 at 20:13
answered Nov 22 at 19:24
Mahi
685319
685319
please have a look at the below example. He is not using any html tag in index.html stackblitz.com/edit/angular-multi-layout-example?file=main.ts
– zaid khan
Nov 22 at 19:29
Read Stackblitz docs- stackblitz.com/docs
– Mahi
Nov 22 at 19:46
add a comment |
please have a look at the below example. He is not using any html tag in index.html stackblitz.com/edit/angular-multi-layout-example?file=main.ts
– zaid khan
Nov 22 at 19:29
Read Stackblitz docs- stackblitz.com/docs
– Mahi
Nov 22 at 19:46
please have a look at the below example. He is not using any html tag in index.html stackblitz.com/edit/angular-multi-layout-example?file=main.ts
– zaid khan
Nov 22 at 19:29
please have a look at the below example. He is not using any html tag in index.html stackblitz.com/edit/angular-multi-layout-example?file=main.ts
– zaid khan
Nov 22 at 19:29
Read Stackblitz docs- stackblitz.com/docs
– Mahi
Nov 22 at 19:46
Read Stackblitz docs- stackblitz.com/docs
– Mahi
Nov 22 at 19:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436869%2fwhy-app-root-is-not-a-known-element-with-out-body-tag%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
This would be an interesting opportunity for you to follow the stack trace and dive into the Angular source code to see how it is finding the root element.
– Ben Steward
Nov 22 at 19:39
Yeah dude, and I’m saying the source code may answer his question and reveal some interesting tidbits about how else he might do whatever he is trying to do.
– Ben Steward
Nov 22 at 20:03
Possible duplicate of Angular2 - Error: The selector "app-root" did not match any elements
– Mahi
Nov 22 at 20:13