J
J
JIakki2016-06-23 11:53:27
JavaScript
JIakki, 2016-06-23 11:53:27

How to make a module from a component in angular 2?

For example, I have a component:

import { Component, Input, Output, EventEmitter } from '@angular/core';

@Component({
        moduleId: module.id,
  selector: 'shop-checkbox',
  styles: [require('./checkbox.component.css')],
  template: require('./checkbox.component.html'),
})

export class CheckboxComponent {
  @Input() checked: boolean;
  @Output() change = new EventEmitter();

  changeCheckbox() {
    this.checked = !this.checked;
    this.change.emit(this.checked);
  }
}

<div class='checkbox' 
  [ngClass]='{active: checked}' 
  (click)='changeCheckbox()'>

  <div class='view'></div>
  <span>Name {{checked}}</span>

</div>

.checkbox.active .view {
  background-color: blue;
}

If this module is placed in node_modules, then the error 'Expected 'styles' to be an array of strings.' with styles: [require('./checkbox.component.css')];
a if styleUrls: [./checkbox.component.css']then the problem is with the paths;
How to be?
Thanks for the answer

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nuctoh, 2016-10-28
@nuctoh

As I understand it, your checkbox.component.css is in the same folder as the module. If so, then your decorator says
moduleId:
module.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question