To resolve this error, we need to type the below command,
npm cache clean --force
This command is forcefully cleaning the cache.
package.json
------------
{
"name": "multiplecomponent",
"description": "Example Of Multiple Components",
"dependencies": {
"@angular/core": "latest",
"@angular/common": "latest",
"@angular/compiler": "latest",
"@angular/platform-browser": "latest",
"@angular/platform-browser-dynamic": "latest",
"rxjs": "6.0.0",
"zone.js": "latest",
"systemjs": "latest",
"core-js": "latest"
}
}
systemjs.config.js
------------------
System.config({
map:{
"app":"scripts",
"@angular/core":"node_modules/@angular/core/bundles/core.umd.js",
"@angular/common":"node_modules/@angular/common/bundles/common.umd.js",
"@angular/compiler":"node_modules/@angular/compiler/bundles/compiler.umd.js",
"@angular/platform-browser":"node_modules/@angular/platform-browser/bundles/platform-browser.umd.js",
"@angular/platform-browser-dynamic":"node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js",
"rxjs":"node_modules/rxjs"
},
packages:{
"app":{main:"./app"},
"rxjs":{}
}
});
tsconfig.json
-------------
{
"compilerOptions": {
"target": "es5",
"sourceMap": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"lib": [
"es2015","dom"
]
}
}
componentstyle.css
------------------
div{
font-size: x-large;
}
bodycontent.html
----------------
<div>
Angular Rocks!!
</div>
index.html
----------
<html>
<head>
<script src="node_modules/core-js/client/shim.js"></script>
<script src="node_modules/systemjs/dist/system.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import("scripts").catch(function(ex){
console.log("Error With SystemJS Loader File");
});
</script>
</head>
<body>
<header>Loading Header...</header>
<br>
<bodyinfo>Loading Body...</bodyinfo>
</body>
</html>
Syntax:-
----------
@Component({
selector : Specify element name to component,
template : Specify inline markup to component,
templateUrl : Specify html markup to component,
style : Specify inline style to component,
styleUrl : Specify external style to component
})
class classname
{
variable declarations
method declarations
}
Example:-
------------
@Component({
selector : "my-app",
template : "<h2>Welcome to Angular 2</h2>";
style : ["h2{color:red}"]
})
class appComponent
{}
package.json
---------------
{
"name":"myproject",
"description":"my angular 5 project",
"dependencies":{
"@angular/core":"latest",
"@angular/common":"latest",
"@angular/compiler":"latest",
"@angular/platform-browser":"latest",
"@angular/platform-browser-dynamic":"latest",
"rxjs":"latest",
"zone.js":"latest",
"systemjs":"latest",
"core-js":"latest"
}
}
tsconfig.json
---------------
{
"compilerOptions": {
"target": "es5",
"sourceMap": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"lib": [
"es2015","dom"
]
}
}
app.ts
-------
import {Component,NgModule} from "@angular/core";
import {BrowserModule} from "@angular/platform-browser";
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
@Component({
selector:"my-app",
template:"<h2> Hello World </h2>"
})
class AppComponent{}
@NgModule({
declarations:[AppComponent],
imports:[BrowserModule],
bootstrap:[AppComponent]
})
class AppModule{}
platformBrowserDynamic().bootstrapModule(AppModule);
index.html
-------------
<html>
<head>
<script src="node_modules/core-js/client/shim.js"></script>
<script src="node_modules/systemjs/dist/system.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import("scripts").catch(function(ex)
{
console.log("error with SystemJS module loader file");
});
</script>
</head>
<body>
<h1>Angular First Example</h1>
<my-app>Loading Component...</my-app>
</body>
</html>
The content is strictly copyrighted to the Admin and may not be reproduced without permission.
© 2017 Designed by DotNet Developer