How to get an instance variable from rails using a

2019-07-05 03:29发布

问题:

I'm using a template in my state router. I want to get an instance variable from my rails server, but it doesn't have it's own path, so I can't use Restangular or something like that. Also, when I try to interpolate:

#{@variable}

nothing happens, because I'm in a template in my ui router, and not in a rails view.

So how do I get an instance variable from my rails server into angularjs in a ui-router template?

EDIT:

ahaa.... just pass it in like this:

 ng-init="variablename = 'variable'"

so in my case:

ng-init="varname = '#{@variable}' "   

what's important to notice is two things: 1. the '' within the "" 2. pass this in on your RAILS VIEW, BEFORE you hand it off to the ui router with ui-view=""

then in the ui template, you can just say {{varname}} and it should be there :)