Thursday, 2 June 2016

35. Angularjs : CaseInsensitiveMatch & Inline Templates


              Angularjs provide 2 features( CaseInsensitiveMatch && Inline Templates) which very useful in web application angularjs projects.

CaseInsensitiveMatch

           Bydefault routes which we define in .config() are case-sensitive. when try to access a route using Uppercase or Lowercase which is not exactly defined in $routeProvider. angular will simply ignore this. means angular not handles case sensitive nature.

               so that to handle this we config object has a property is caseInsensitiveMatch : true. 

.when("/courses",
 {
    templateUrl: "Templates/Courses.html",
    controller: "Coursescontroller",
    caseInsensitiveMatchtrue
 })
NOW We can access this route using /course or /COURSES also.

i want provide this caseInsensitiveMatch to entire my config routes then (instead of writing every route like above set caseInsensitiveMatch at route level.

   $routeProvider.caseInsensitiveMatch=true;
   $routeProvider.when(.....);

we any route any case(upper/lower) it works.

InlineTemplates :

   tell now seen templateUrl of $routeProvider is an html file. like bleow  -I & II

            $routeProvider.when("/home",
                                          { templateUrl: "Templates/Home.html", -----I
                                            controller: "Homecontroller",
                                            controllAs: "HomeCtrl"})
                                         .when("/courses",
                                          {
                                              templateUrl: "Templates/Courses.html",------II
                                              controller: "Coursescontroller",
                                              caseInsensitiveMatch: true
                                          })
so content of view coming from sprated html files. there is not rule content of templateUrl should be an html file.

templatUrl  allows to write content of view inline itself also.

$routeProvider.when("/home",
                   {
                     template: "<h2>Inline content not from html file</b></h2>",
                     controller: "Homecontroller"
                })
this time we used template property not templateUrl Property.

                       

No comments:

Post a Comment