I am using angular-cli in my project and when I run commands below like-
ng g c componentName
then,
a component is created with some default text like below- @Component({}) etc
component.ts
import { Component } from '@angular/core';
@Component({
selector: '',
templateUrl: '',
styleUrls: ['']
})
export class component implements OnInit{
constructor(){}
ngOnInit() {}
}
How does this text created by default when component is created?
Can we create our own custom commands for component generation with default text inside component.ts and component.html(like below)?
custom.component.ts
import { Component } from '@angular/core';
@Component({
selector: '', <-----name as provide in command
templateUrl: '',
styleUrls: ['']
})
export class component implements OnInit{
constructor(){}
title = 'Welcome to component ';
size: 500;
width: 1000;
height:500;
'
'
'
ngOnInit() {
if (this.data) {
this.buildChart(this.data);
}
// For Default Data from json
else {
try {
let self = this;
this.jsonDataService.getChartDefaultData().subscribe(
function (success) {
self.data = success;
self.buildChart(success);
},
error => console.log('Getting Server Data Error :: ' + JSON.stringify(error)));
} catch (e) { console.error('Error :: ' + JSON.stringify(e)); }
}
}
}
custom.component.html
Welcome to component template.