Does latest version of Angular cli supports inline templates and css for components ? i dont see --inline-template option there anymore ?
https://github.com/angular/angular-cli
you can use the cli "ng g c component-name -is -it" to create a component with inline styles and inline template.
But when we want to generate component with inline template and style we have to provide two options after the above command. For inline templates, we need to add --inlineTemplate=true. By default its value is false. For inline style, we need to add --inlineStyle=true.
An inline HTML template for a component is defined using template config in @Component decorator, as shown below. It can be a single line template wrapped inside double quotes or single quotes. It can also be a multi-line template wrapped inside backticks char `.
In your angular-cli.json file you can specify if you want your files to have inline css and templates.
Here you can find all the options that you can specify in the config file.
https://github.com/angular/angular-cli/wiki/angular-cli
That way, when you use ng generate component
it will use the defaults.
{
"project": {
"version": "1.0.0-beta.22-1",
"name": "client"
},
"apps": [
{
"root": "src",
"outDir": "build",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "ws",
"mobile": false,
"styles": [
"styles/main.scss"
],
"scripts": [],
"environments": {
"source": "environments/environment.ts",
"prod": "environments/environment.prod.ts",
"dev": "environments/environment.dev.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "scss",
"prefixInterfaces": false,
"inline": {
"style": true, <<<--- CHECK IT OUT!!
"template": true
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
In the current version of the CLI (version 6) I just created a new project with ng new foo -s -t
. The -s
and -t
set the defaults for inline templates and inline styles to true. Then I opened the angular.json
and looked at what it did.
Inside of the "project"
property of each app... there is a "schematics"
property. Inside of that, it added the following:
"@schematics/angular:component": {
"inlineTemplate": true,
"inlineStyle": true
}
If you add this, and then attempt to generate a component, the template and the styles will default to inline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With