Skip to content

Allows to override templates loaded via ui-router state.templateUrl

License

Notifications You must be signed in to change notification settings

alQlagin/angular-template-url-provider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

templateUrlProvider

Allows to override templates loaded via ui-router state.templateUrl

Get Started

install via bower

bower install angular-template-url-provider

Add 'ui.router.templateProvider' to your app dependencies

    var myApp = angular.module('myApp', ['templateUrlProvider']);

Usage

module allows override state templates in your dependency modules without thinking about $templateCache

Configuring

In config phase add TemplateUrlProvider and assign replaces

    /**
    * first is url to override, second is your template url
    */
    angular.module('app', ['templateUrlProvider'])
    .config(['TemplateUrlProvider', function(TemplateUrlProvider){
        TemplateUrlProvider.replace('vendor/my-module/views/template.html', 'my-theme/views/my.module.template.html')
    }])

This can be useful when need to overload 3rd party templates:

    /**
    *  replace default bootstrap alert template with own  
    */
    TemplateUrlProvider.replace('uib/template/alert/alert.html', 'views/bootstrap/alert.html')

Also this can be used for ui.router' when state template mey be overridden

Configure your states with templateProvider instead of templateUrl like so

$stateProvider
    .state('stateName', {
            url: '/',
            templateProvider: [
                'TemplateUrl', 
                function (TemplateUrl) {
                    return TemplateUrl.provide('bower_components/vendor/my-module/views/template.html')
                        .then(function (r) {
                            return r.data
                        })
                }
            ],
    })

and reassign template bower_components/vendor/my-module/views/template.html in main application

    /**
    * first is url to override, second is your template url
    */
    TemplateUrlProvider.replace('bower_components/vendor/my-module/views/template.html', 'my-theme/views/my.module.template.html')

About

Allows to override templates loaded via ui-router state.templateUrl

Resources

License

Stars

Watchers

Forks

Packages

No packages published