Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Cli support for inline templates and css

Tags:

angular-cli

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

like image 466
ATHER Avatar asked Dec 14 '16 23:12

ATHER


People also ask

What is the angular CLI command to create a component using inline template and inline style?

you can use the cli "ng g c component-name -is -it" to create a component with inline styles and inline template.

What is the command to generate a component with inline HTML & inline stylings?

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.

How would you define an inline template in angular component with multiple lines?

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 `.


2 Answers

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
      }
    }
  }
like image 171
Leon Radley Avatar answered Oct 27 '22 09:10

Leon Radley


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.

like image 22
frosty Avatar answered Oct 27 '22 11:10

frosty