javascriptangularjsangular-ui-routerangular-templatecache

Using $templateCache with ui-router and uglify in angular 1.x


Sharing this as a Qusstion-answer post.

What to do when you have to use $templateCache in templateProvider of a route in ui-router and have to utility the code? Injecting does not work, and angular cannot inject by reference.

Example :

...  
templateProvider : function($templatecache) {

    ...

},

...

Solution

  • Use this instead :

    ...  
    templateProvider : ['$templateCache', function($templateCache) {
    
        ...
    
    }],
    
    ...