These are chat archives for AngularClass/angular2-webpack-starter

25th
Mar 2017
webdev48
@webdev48
Mar 25 2017 00:21
I am using this starter kit trying to read a simple json file from a service...it throws 404
can anyone help?
export class MyService {

  public data:any;

  constructor(private http:Http) {
    this.http.get('/data/settings.json')
      .subscribe(res => this.data = res.json());
  }
}
Forrest Murray
@FMurray
Mar 25 2017 01:31
@webdev where are you using the service? did you add it to the providers?
webdev48
@webdev48
Mar 25 2017 01:50
yes all of that is fine... obviously i am consuming it in a component

@Component({
  selector: 'home',  // <home></home>
  providers: [
    MyService
  ],
  styleUrls: [ './home.component.css' ],
  templateUrl: './home.component.html'
})
export class HomeComponent implements OnInit {

  // TypeScript public modifiers
  constructor(
    public myService: MyService
  ) {
    console.log(myService.data);

  }
}
Forrest Murray
@FMurray
Mar 25 2017 01:52
Is that all the code? \
You need to use @Injectable decorator I believe
webdev48
@webdev48
Mar 25 2017 01:53
im using that as well on the service
Forrest Murray
@FMurray
Mar 25 2017 01:58
.subscribe(res => this.data = res.json().data)
webdev48
@webdev48
Mar 25 2017 02:00
already doing that in the service if you look above ^^ and it does not need .data in the end
its a 404 dude EXCEPTION: Response with status: 404 Not Found for URL: http://localhost:4000/data/settings.json
Carlos Esteban Lopez Jaramillo
@luchillo17
Mar 25 2017 17:45
Anyone can explain me what does this do in webpack config?
// Fix Angular 2
      new NormalModuleReplacementPlugin(
        /facade(\\|\/)async/,
        helpers.root('node_modules/@angular/core/src/facade/async.js')
      ),
      new NormalModuleReplacementPlugin(
        /facade(\\|\/)collection/,
        helpers.root('node_modules/@angular/core/src/facade/collection.js')
      ),
      new NormalModuleReplacementPlugin(
        /facade(\\|\/)errors/,
        helpers.root('node_modules/@angular/core/src/facade/errors.js')
      ),
      new NormalModuleReplacementPlugin(
        /facade(\\|\/)lang/,
        helpers.root('node_modules/@angular/core/src/facade/lang.js')
      ),
      new NormalModuleReplacementPlugin(
        /facade(\\|\/)math/,
        helpers.root('node_modules/@angular/core/src/facade/math.js')
      ),