Angular Training
Rafał Brzoska
Brown Brothers Harriman
Kraków 12-13.01.2018
Rafał Brzoska
Angular Trainer
Software Developer @ Future Processing
module.exports = {
entry: './main.js',
output: {
path: __dirname + '/dist',
filename: '[name].bundle.js'
},
module: {},
plugins: []
};
entry: './main.js',
entry: {
main: './main.js',
libs: './libs.js',
adv: './adv.js'
}
output: {
path: __dirname + '/dist',
filename: '[name].bundle.js',
chunkFilename: '[id].chunk.js'
}
module: {
rules: [
{
//typy plików które mają zostać 'załadowane'
test: /\.css$/,
//jeden wybrany loader
use: 'loader1',
// lub tablica loaderów ktore wykonywane są
//w kolejnosci OD PRAWEJ DO LEWEJ
use: ['loader1', 'loader2', 'loader3']
]
}
plugins: [
new HtmlWebpackPlugin(),
new ExtractTextPlugin('styles.css')
]
"dependencies": {
"@angular/common": "^5.2.6",
"@angular/compiler": "^5.2.6",
"@angular/core": "^5.2.6",
"@angular/forms": "^5.2.6",
"@angular/http": "^5.2.6",
"@angular/platform-browser": "^5.2.6",
"@angular/platform-browser-dynamic": "^5.2.6",
"@angular/router": "^5.2.6",
"core-js": "^2.5.3",
"rxjs": "^5.5.6",
"zone.js": "^0.8.20"
},
"devDependencies": {
"@angular/cli": "^1.7.1",
"@angular/compiler-cli": "^5.2.6",
"@ngtools/webpack": "^1.10.1",
"@types/node": "^9.4.6",
"angular2-template-loader": "^0.6.2",
"tslint": "^5.9.1",
"typescript": "^2.6.2",
"url-loader": "^0.6.2"
...
}
{
"compilerOptions": {
"baseUrl": ".",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"lib": ["dom", "es2016"],
"module": "es2015",
"moduleResolution": "node",
"noEmitHelpers": true,
"skipLibCheck": true,
"suppressImplicitAnyIndexErrors": true,
"typeRoots": [
"node_modules/@types"
]
},
"angularCompilerOptions": {
"entryModule": "src/app/app.module#AppModule",
"genDir": "./ngfactory"
}
}
ng new my-project
ng eject
|
import './polyfills';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { registerAsCustomElements } from '../@angular/elements';
import { AppModule, customElements } from './app/app.module';
registerAsCustomElements(customElements, () => {
return platformBrowserDynamic().bootstrapModule(AppModule);
})
.then(() => {
// App is bootstrapped
}, (error) => {
// There's a bootstrapping error
});
export const customElements = [
CustomComponent
];
@NgModule({
declarations: [
...customElements
],
imports: [
BrowserModule
],
entryComponents: [...customElements]
})
export class AppModule {
ngDoBootstrap() { }
}
var elem = document.querySelector('custom-component');
elem.addEventListener('myMethod', function (ev) {
console.log(ev.detail)
})
ng generate
Component | ng g component my-new-component |
Directive | ng g directive my-new-directive |
Pipe | ng g pipe my-new-pipe |
Service | ng g service my-new-service |
Class | ng g class my-new-class |
Guard | ng g guard my-new-guard |
Interface | ng g interface my-new-interface |
Enum | ng g enum my-new-enum |
Module | ng g module my-module |
https://github.com/angular/angular-cli/wiki
@Component({
changeDetection?: ChangeDetectionStrategy
viewProviders?: Provider[]
moduleId?: string
templateUrl?: string
template?: string
styleUrls?: string[]
styles?: string[]
animations?: any[]
encapsulation?: ViewEncapsulation
inputs?: string[]
outputs?: string[]
host?: {...}
providers?: Provider[]
exportAs?: string
queries?: {...}
})
get(url: string, options: {
headers?: HttpHeaders | {
[header: string]: string | string[];
};
observe?: HttpObserve;
params?: HttpParams | {
[param: string]: string | string[];
};
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
} = {}): Observable<any>