Skip to content

Instantly share code, notes, and snippets.

@gmocamilotd
Last active September 28, 2017 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmocamilotd/1f3ebe87d6c4526e875a8e549f8da308 to your computer and use it in GitHub Desktop.
Save gmocamilotd/1f3ebe87d6c4526e875a8e549f8da308 to your computer and use it in GitHub Desktop.
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);
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment