Angularjs: routes and controllers without templateURLs?

后端 未结 3 1679
执念已碎
执念已碎 2021-01-23 08:10

Is it possible to use Angularjs\'s routing and controller without the templateURL?

For instance, below is my current routes, controllers, and template urls,



        
3条回答
  •  感动是毒
    2021-01-23 08:50

    Angular uses the $routeProvider Definition to attach a controller to your view. If you don't want to specify the details in $routeProvider config, other option is to let the application land on one page using something like -

      .config(function ($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/main.html'
      })
        .when()
        .otherwise({
        redirectTo: '/'
      });
    

    });

    This way user will land on main.html. Now on the main.html you can include several different html templates like -

     

    Notice the syntax of using/including template above - "'<>'"

    Hope this helps.

提交回复
热议问题