Understanding root scope

1,193 views
Skip to first unread message

Luther Goh Lu Feng

unread,
Feb 1, 2011, 1:17:38 AM2/1/11
to Angular
I am new to angularjs and have been reading the documentation.

I am trying to understand what is meant by 'root scope'. I have looked
at http://angularjs.org/Scope. Also is 'root scope' specific to
angularjs or applies to javascript in general?

My current understanding of 'root scope' is that it is the outer most
parent scope. Is this correct?

Igor Minar

unread,
Feb 1, 2011, 11:33:33 AM2/1/11
to ang...@googlegroups.com
On Mon, Jan 31, 2011 at 10:17 PM, Luther Goh Lu Feng <elf...@yahoo.com> wrote:
> I am new to angularjs and have been reading the documentation.
>
> I am trying to understand what is meant by 'root scope'. I have looked
> at http://angularjs.org/Scope. Also is 'root scope' specific to
> angularjs or applies to javascript in general?

It's an angular concept.

>
> My current understanding of 'root scope' is that it is the outer most
> parent scope. Is this correct?

that's correct.

/i

Luther Goh Lu Feng

unread,
Feb 1, 2011, 1:07:17 PM2/1/11
to Angular


On Feb 2, 12:33 am, Igor Minar <iimi...@gmail.com> wrote:
> On Mon, Jan 31, 2011 at 10:17 PM, Luther Goh Lu Feng <elf...@yahoo.com> wrote:
>
> > I am new to angularjs and have been reading the documentation.
>
> > I am trying to understand what is meant by 'root scope'. I have looked
> > athttp://angularjs.org/Scope. Also is 'root scope' specific to
> > angularjs or applies to javascript in general?
>
> It's an angular concept.
>
>
>
> > My current understanding of 'root scope' is that it is the outer most
> > parent scope. Is this correct?
>
> that's correct.
>
> /i

So does that mean that a html page can have more than one root scope?

Misko Hevery

unread,
Feb 1, 2011, 1:13:43 PM2/1/11
to ang...@googlegroups.com
in theory yes. You could turn ouf ng:autobind and then you could attach angular to more then one element, in which case each of these elements will have a separate root scope, and the two angular apps will be independent.


--
You received this message because you are subscribed to the Google Groups "Angular" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.


Ruiwen Chua

unread,
Feb 5, 2011, 4:25:30 AM2/5/11
to Angular
Is there a way to manually control which element angular binds to?

Say, I have <div id="content">, and at one point in the app I would
like to have it controlled by WorkspaceController. Then after some
user input, I would like <div id="content"> to now be controlled by
AnswerController. The desired effect of which is that, if
AnswerController defines a list that wasn't present in
WorkspaceController, then I would like the list in the HTML template
to be populated once the controller switches.

Is that possible?
> > angular+u...@googlegroups.com<angular%2Bunsu...@googlegroups.com >
> > .

Igor Minar

unread,
Feb 5, 2011, 11:20:38 AM2/5/11
to ang...@googlegroups.com
why not just use $route and ng:view or ng:include?

/i

> To unsubscribe from this group, send email to angular+u...@googlegroups.com.

Ruiwen Chua

unread,
Feb 6, 2011, 3:40:26 AM2/6/11
to Angular
Ok, let's see if I understand it correctly.

Assuming I have :

=== javascript ====

$route.when('/inbox/', {template: '/inbox.html', controller:
InboxController});
$route.when('/inbox/msg/:mid/', {template: '/message.html',
controller: MessageController});

=============

and

===== template =====

<div id="content">
<ng:view></ng:view>
</div>

==================

The <ng:view> will be replaced with either "/inbox.html" or "/
message.html" depending on the $route and be controlled by the
appropriate Controller?

In the next case, assuming I have content in the sidebar that I would
like to change in accordance to which $route is currently active, like
so:

===== sidebar template =====

<div id="container">
<div id="content">
<ng:view></ng:view>
</div>

<div id="sidebar">
<ng:view></ng:view>
</div>
</div>
========================

Is there a way for a Controller to take control of two separate
<ng:view>s? Or do I have to replace the entire partial in <div
id="container">?

Thanks for the help!

//Ruiwen

Misko Hevery

unread,
Feb 6, 2011, 11:06:37 AM2/6/11
to ang...@googlegroups.com
ng:view is thightly bound to $route
but ng:include is a generic way to include other templates/controllerls:

In your case your main controller will create a child controrller and a url which will then be passed to ng:include.

-- Misko
Reply all
Reply to author
Forward
0 new messages