Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 Web Pack 404 Html Template Urls

I'm using Angular2 RC4 version and webpack dev server. I'm not able to successfully load my application. On the browser console it throws 404 and fails to load AppComponent template file using webpack. This works if I use lite-server

app.component.ts snippet

@Component({
    moduleId:module.id,
    selector: 'body',
    templateUrl: 'app.component.html',
})

webpack.config.js snippet

 module:{
       loaders:[
            {test:/\.ts$/, loader:'ts',   exclude: /node_modules/},
            {test:/\.html$/, loader:'html' },
       ],

    },

Error browser_adapter.js?0526:84Error: Uncaught (in promise): Failed to load /app.component.html

like image 437
Robin Kedia Avatar asked Jan 05 '23 18:01

Robin Kedia


2 Answers

Another option is to use awesome-typescript-loader in combination with angular2-template-loader to inline all your styles for you, and you don't need require.

https://github.com/TheLarkInn/angular2-template-loader

  module: {
    loaders: [
      {
        test: /\.ts$/,
        loaders: ['awesome-typescript-loader', 'angular2-template-loader'],
        exclude: [/\.(spec|e2e)\.ts$/]
      }
    ]
  },
like image 159
Mark Pieszak - Trilon.io Avatar answered Jan 24 '23 14:01

Mark Pieszak - Trilon.io


In case of Angular2 webpack,

Use template like this-

  template: require('./app.component.html'),
  styles: [require('./app.component.css')]

instead of

  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']

See if this helps.

like image 33
Sanket Avatar answered Jan 24 '23 15:01

Sanket