Bind same Javascript object to different html

30 views
Skip to first unread message

biswarup dasgupta

unread,
Jan 7, 2015, 4:47:15 AM1/7/15
to ang...@googlegroups.com
Hi,

Is there any way to bind the same javascript object to different html pages apart from having the object in rootScope ? Any pointers are welcome.

Thanks.

Sander Elias

unread,
Jan 8, 2015, 7:16:51 AM1/8/15
to ang...@googlegroups.com
Hi Biswarup,

I'm not sure I understand what you need, but yes, that is easily possible. However usually this point's to a code smell. 
As I don't know what you are looking for, I can't be of much help.

If you would build a plunk of what it is you are trying to do, you are probably getting more helpfull answers ;)

Regards
Sander

Tony pee

unread,
Jan 9, 2015, 11:30:02 PM1/9/15
to ang...@googlegroups.com
Have it in a service, and have a reference to the service on any controller (therefore scope) that you want to bind it into the html
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


--
Tony Polinelli


Em Smitley

unread,
Jan 10, 2015, 9:45:48 PM1/10/15
to ang...@googlegroups.com
Why not just create a directive? Just restrict : 'A' and put the attribute on each html element you want to bind to?

Cornelius Kölbel

unread,
Jan 11, 2015, 1:06:34 AM1/11/15
to ang...@googlegroups.com
You might also create a service.
I needed access to a rest api in all my controllers, so creating a service was the right choise.
Your service can also provide a simple object.
A service is always a singleton, so you will have one unique object throughout your whole app.

Kind regards
Cornelius

On Wednesday, January 7, 2015 at 1:47:15 AM UTC-8, biswarup dasgupta wrote:
Hi,

Is there any way to bind the same javascript object to different html pages apart from having the object in rootScope ? Any pointers are welcome.

Thanks.
-- 
signature.asc

Em Smitley

unread,
Jan 11, 2015, 6:41:56 AM1/11/15
to ang...@googlegroups.com
Ahhh okay that makes sense. Yeah connecting to a rest api probably shouldn't be handled in a directive lol.

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/2UGRztAin2U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages