The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Tachyon80 (10) [Avatar] Offline
#1
I'm in chapter 2 pg. 41. Listing 2.7 is different from what I'm seeing. I'm using Angular CLI v7.1.3

src/app/components/summary/summary.component.ts
What the CLI generated for me is:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-summary',
  templateUrl: './summary.component.html',
  styleUrls: ['./summary.component.scss']
})
export class SummaryComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}


My Questions:
1) Do I need to add
import { Component, Input ) from '@angular/core';
? When I tried my IDE (PhpStorm) told me it was a conflict.

2) How do I handle the line:
@Input() stock: any;
Do I put this into ngOnInit() somehow? I'm confused on this one.

Any help would be greatly appreciated. Thank you for your time.
Tachyon80 (10) [Avatar] Offline
#2
I learned from StackOverflow Input and OnInit don't conflict. The fixed example is:
import { Component, OnInit, Input } from '@angular/core';

@Component({
  selector: 'app-summary',
  templateUrl: './summary.component.html',
  styleUrls: ['./summary.component.scss']
})
export class SummaryComponent implements OnInit {
  @Input() stock: any;
  constructor() { }
  ngOnInit() {
  }
  isNegative() {
    return (this.stock && this.stock.change < 0);
  }
  isPositive() {
    return (this.stock && this.stock.change > 0);
  }
}
563822 (6) [Avatar] Offline
#3
I don't have any problem either but I am using VS Code.