0

I have the following ui-router configuration in my angular app:

app.config(["$stateProvider", function ($stateProvider) {
  $stateProvider
    .state("state1", {
      controller: "controller",
      templateUrl: "mytemplate.html"
    })

app.controller("controller"....

In the controller I call a google cloud endpoint API:

gapi.client.myapi.method().then(function (resp){

}, function (error) {

});

How can I add html using the data from the API response? Is using a directive the best approach?

UPDATE:

I forgot to mention that the response is from an insert method, this means that this will be executed several times, and each time I need to add the response to the existing elements, like in a timeline way.

6
  • 1
    Is data going to be array and do u want to create a HTML template for it? Commented Oct 24, 2016 at 2:42
  • 1
    Best way to do what specifically? Question is not clear. Please review How to Ask Commented Oct 24, 2016 at 2:56
  • Possible duplicate of Angular Js and google api client.js (gapi) Commented Oct 24, 2016 at 3:07
  • How about using route resolve? Commented Oct 24, 2016 at 4:35
  • @Shankar Shastri yes I do want to create an HTML template, that's what I was thinking of use a directive. Commented Oct 24, 2016 at 5:04

1 Answer 1

0

You can use ngBindHtml incase your response is HTML or bind the response to your template using {{variableName}} inside your mytemplate.html

Directives are preferred if that piece of code is to be used in multiple screens and is also a good practice for big projects.

Thanks, Abhishek Jain.

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

Comments

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.