Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught Error: No template specified for component MyApp

I am trying to update my ionic 2 Beta 2 code to ionic 2 RC0 and am getting a No template specified error in my app.component.ts file.

The relevant part of the app.component.ts file looks like this:

@Component({
    templateUrl: 'app.html',
})

export class MyApp {
    rootPage: any = HomePage;
    loggedIn:boolean = false;

    @ViewChild(Nav) nav: Nav;

    root: any;// = HomePage;


    constructor() {
        ...
    }
}

According to the update instructions for updating an app to release candidate 0 for ionic 2 the app.html file is in the same directory as the app.component.ts file and the path is app.html

When running the ionic app both Firefox and Chrome complain that no template has been specified for app.component.

like image 644
Bill Noble Avatar asked Oct 08 '16 19:10

Bill Noble


2 Answers

I had the same problem and what was causing was a commented line. I suggest that answer even if you didn't include a commented line in your example (I supposed that you didn't imagine that a commented line could cause the error). The following produced the same error as you :

@Component({
    //template: `<ion-nav [root]="rootPage"></ion-nav>`  
    templateUrl: 'app.html'
})

I had to do the following change for the compilation to work (while using ionic-app-scripts @ 0.0.30, I have the feeling that the problem appeard between v0.0.23 and v0.0.30, but I didn't investigate) :

@Component({
  templateUrl: 'app.html'
  //template: `<ion-nav [root]="rootPage"></ion-nav>`
})
like image 180
apiaget Avatar answered Oct 19 '22 20:10

apiaget


In layman terms, in your component.ts file add templateURL. Follow the code snippet as follows :-

@Component({
  selector: 'app-securelogin-receiver',
  templateUrl: './securelogin-receiver.component.html',
  providers: [SecureloginService]
})

Which is being referred at the time of component load, hence its unavailability throws exception.

Error: No template specified for component SecureloginReceiverComponent

above exception i got in templateURL's absence.

like image 41
codechefvaibhavkashyap Avatar answered Oct 19 '22 21:10

codechefvaibhavkashyap