Install Angular 4 without CLI

Step 1 : npm init

-- This will create a package.json file

Step 2 : Copy the content of the below package.json in the created file

Step 3 : npm install

Step 4: Create Controller , Module ,main.ts ,tsconfig.json,systemjs.config.js,files from the below link

Step 5: install http-server --save-dev -- This will add an entry in the package.json file

Step 6: http-server -p 8090 --  run the application -- Access the application http:localhost:8090/index.htm

Git Link : https://github.com/mazuami/Angular4Structure.git


tsconfig.js

{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}

systemjs.config.js

(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},

// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',

// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

// other libraries
'rxjs': 'npm:rxjs',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);


index.htm

<!DOCTYPE html>
<html>
<head>
<title>Angular 2 Hello World</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>

<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>

<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>

<body>
<mycomp>I will load Loading...</mycomp>
</body>

</html>

app.module.ts
import {NgModule} from '@angular/core';
import {BrowserModule } from '@angular/platform-browser';
import {myComponent } from './my.component';

@NgModule({
imports: [BrowserModule],
declarations: [myComponent],
bootstrap: [myComponent]
})

export class AppModule{

}

my.component.ts

import { Component } from '@angular/core'

@Component ({
selector:'mycomp',
template: '<strong>Hello World</strong>'

})

export class myComponent {

}

main.ts
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; //JIT Compiler
import {AppModule} from './app.module';

platformBrowserDynamic().bootstrapModule(AppModule);

package.json

{
"name": "angular2app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Amit M",
"license": "ISC",
"dependencies": {
"@angular/common": "^4.0.1",
"@angular/compiler": "^4.0.1",
"@angular/core": "^4.0.1",
"@angular/forms": "^4.0.1",
"@angular/http": "^4.0.1",
"@angular/platform-browser": "^4.0.1",
"@angular/platform-browser-dynamic": "^4.0.1",
"@angular/router": "^4.0.1",
"core-js": "^2.4.1",
"rxjs": "^5.3.0",
"systemjs": "^0.20.12",
"zone.js": "^0.8.5"
},
"devDependencies": {
"@types/node": "^7.0.12",
"http-server": "^0.9.0",
"typescript": "^2.2.2"
}
}

Comments

Popular posts from this blog

Authentication and Authorization in Web API -Part1

My Gardening Journey 6