gmocamilotd
9/20/2017 - 12:23 AM

errores para angular

angular, errorfix

Can't bind to 'ngModel' since it isn't a known property of 'input'

resuelve

Yes that's it, in the app.module.ts, I just added :

import { FormsModule } from '@angular/forms';

[...]

@NgModule({
  imports: [
    [...]
    FormsModule
  ],
  [...]
})

Directives is not assignable to parameter of type 'Component'

este codigo:

import { Component } from '@angular/core';
import { HeaderComponent } from './components/header/header.component'
@Component({
  selector: 'my-app',
  template: '<h1>Hello</h1><header></header>',
  directives: [HeaderComponent]  <== here 
})
export class AppComponent { }

resuelve:

directives property has been removed in RC.6

You should move it to declarations property of your NgModule decorator

@NgModule({
  imports:      [ BrowserModule ],
  declarations: [ AppComponent, HeaderComponent ], <== here
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

@angular/http/index has no exported member of HTTP_PROVIDERS

resuelve:

HTTP-PROVIDERS is not used anymore. Import HttpModule to your ngModule instead and add it to your imports.
import { HttpModule } from '@angular/http';

@NgModule({
  imports: [
    ...
    HttpModule,   <=== nota esto
  ],
  declarations: [...],
  bootstrap: [ .. ],
  providers: [ ... ],
})

get title list from json placeholder (jsonplaceholder)

resolve:

Step 1. Create A service

import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import  'rxjs/add/operator/map';
import  'rxjs/add/operator/do';
import  'rxjs/add/operator/catch';

@Injectable()
export class ProductService{
  private _productUrl = 'api url';
  constructor (private _http:Http){}

  getProductsHttp():Observable<any> {
      return this._http.get(this._productUrl)
          .map((response: Response) => <any> response.json())
          .do(data => console.log('All: ' +  JSON.stringify(data)))
          .catch(this.handleError);
  }

  private handleError(error: Response) {
      console.error(error);
      return Observable.throw(error.json().error || 'Server error');
  }

Step 2 Change the Component like below

constructor(private _producrService:ProductService)  {

}
ngOnInit() {
      this._producrService.getProductsHttp()
            .subscribe(products => this.products = products,
                       error => this.errorMessage = <any>error);

}