Angular JS Undefined Variable on View

86 Views Asked by At

I have a service call to backend (server side) code which returns the content. I need to send the list of content id to server and server returns back all the content. Then I display those content on view (html page) as follows.

call service with following list of content id

contents :[
'SEARCH', 'HELP'
]

Then server returns

contents: {
'SEARCH' : 'Search Text',
'HELP' : 'Help Text',
} 

Now I use those contents in angular view as

{{contents.SEARCH}}

So it prints this content. But for those code to run I need to send all the content id before view is rendered. For the complete application it will be huge.

As salutation I want to call the backend while a view is being rendered with an undefined content, but it will show the view with that key. After getting the server response that key will be converted with server response content text.

Can anyone please help.

2

There are 2 best solutions below

0
On BEST ANSWER

Thanks for reply. We can solve this issue by $http interceptor. While loading the templates it will check the contents wchich are required. Then also call another http request and upon resolve it will return the original template.

0
On

I hope I understood your problem correctly.

you want to load the data before the View is rendered?

if you use states you can use resolve in the stateprovider states to retrieve the data before the view is getting loaded.

link