1

Please advice how to include(use) commonly used and shared between few projects html files. so html files from external server needs to be included in Angularjs router. Here is a short example of what i have and what i am trying to solve. Now .html is in my project folder:

 .state('chatbase', {
            url: '/cn={cn}',
             onEnter: function ($stateParams, ParamsShareService) {
               ParamsShareService.updateCnValue($stateParams.cn);

            },
            views: {
                'content@': {
                    templateUrl: 'views/chat_wv1.html',
                    controller: 'ChatController'
                }

            }

             })

And i am trying to get them work like this.So i can share the structure for few projects.

 .state('chatbase', {
            url: '/cn={cn}',
             onEnter: function ($stateParams, ParamsShareService) {
               ParamsShareService.updateCnValue($stateParams.cn);

            },
            views: {
                'content@': {
                    templateUrl: 'https://my-website/views/chat_wv1.html',
                    controller: 'ChatController'
                }

            }

             })

1 Answer 1

1

I think the way you implemented it will not work.

templateUrl support explicit path to your project or String.

HTML is a static file with static content. However calling file from HTTP means get file content by using HTTP protocol - different flow and templateUrl doesn't support this way.

Further, Angular state is loaded before any controller and I believe templateUrl: 'views/chat_wv1.html', is what we have today.

You can try this approach (but its a bit complicated):

1) you can load some teplate.html

views: {
            'content@': {
                templateUrl: 'views/teplate.html',
                controller: 'ChatController'
            }
        }

2) The teplate.html will be bind to some Controller that will load HTML content from server and you can use $compile + ng-include to achieve what you look for

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you, what about this thing ` $sceDelegateProvider.resourceUrlWhitelist([ 'website/view.html' ]);`
Here is the link, or am i missing something? w3schools.com/angular/…
@Beny well, its not related to state -> templateUrl
Thank you for your help and advice, i will mark you answer as correct.And will take a look at compile.Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.