Angularjs: routes and controllers without templateURLs?

后端 未结 3 1646
执念已碎
执念已碎 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:48

    Setting template with empty string make error and cause recursion loading ; i solved it by just add the link of empty html file.

     return app.config(['$routeProvider', function ($routeProvider) {
        $routeProvider
        .when("/",
        {
           template: "dummy.htm",
           controller: "controller1"
        })
    
    0 讨论(0)
  • 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 -

     <div ng-include src="'js/template/1.html'" ng-controller = 'Controller1'></div>
     <div ng-include src="'js/template/2.html'" ng-controller = 'Controller2'></div>
    

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

    Hope this helps.

    0 讨论(0)
  • 2021-01-23 09:06

    use template with empty string.

    return app.config(['$routeProvider', function ($routeProvider) {
        $routeProvider
        .when("/",
        {
            template: "",
            controller: "controller1"
        })
    
    0 讨论(0)
提交回复
热议问题