Part 35 AngularJS caseInsensitiveMatch and Inline Templates

來源:互聯網
上載者:User

標籤:efault   int   this   useful   bsp   under   imp   not   templates   

In this video we will discuss 2 simple but useful features in Angular

  • caseInsensitiveMatch 
  • Inline Templates




Let us understand these 2 features with examples. 

caseInsensitiveMatch : The routes that are configured using config function are case sensitive by default. Consider the route below. Notice the route (/home) is lower case. 

$routeProvider    .when("/home", {        templateUrl: "Templates/home.html",        controller: "homeController",        controllerAs: "homeCtrl",    }) 

If we type the following URL in the browser, we will see home.html as expected.
http://localhost:51983/home

If you type the following URL, the you will see a blank layout page. This is because, by default routes are case-sensitive
http://localhost:51983/HOME

To make the route case-insensitive set caseInsensitiveMatch property to true as shown below.

$routeProvider    .when("/home", {        templateUrl: "Templates/home.html",        controller: "homeController",        controllerAs: "homeCtrl",        caseInsensitiveMatch: true    }) 

To make all routes case-insensitive set caseInsensitiveMatch property on $routeProvider as shown below.

$routeProvider.caseInsensitiveMatch = true; 

Inline Templates : The view content for the route (/home), is coming from a separate html file (home.html)

$routeProvider    .when("/home", {        templateUrl: "Templates/home.html",        controller: "homeController",        controllerAs: "homeCtrl",    })

 

Should the view content always come from a separate html file. Not necessarily. You can also use an inline template. To use an inline template use template property as shown below.

$routeProvider    .when("/home", {        template: "<h1>Inline Template in action</h1>",        controller: "homeController",        controllerAs: "homeCtrl"    }) 

At this point, when you navigate to http://localhost:51983/home, you should see Inline Template in action. 

Part 35 AngularJS caseInsensitiveMatch and Inline Templates

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.