267687 (6) [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.
267687 (6) [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);
  }
}