Connect two scopes in AngularJS - kind of

So I'm just starting out with AngularJS and I've got two scopes defined in a controller. In the view I want to have a sort of lookup to the second scope. How's that done?

So more or less - the variable at..

<div class="panel-note">{{ servers.install_id }}</div>

Open in new window

needs to be replaced with {{ notes.installation }} where notes.id = servers.install_id

I hope it makes sense?
MrChrisDavidsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle HamiltonData ScientistCommented:
not sure how you can have two scopes in one controller.  a controller has one scope - that's kind of a basic premise of angular. there are situations where you might end up with some nested scopes within your app, but you would never "define" two scopes in the controller

it's not clear what you are trying to acheive.

can you explain on a higher level what the requirement is, and/or, provide a plunker or jsfiddle with the code in question
0
ambienceCommented:
I suppose you are actually referring to two variables in a scope when you are saying "defined two scopes". Assuming - a lot - and that the scopes are something like

$scope.servers = { 'install_id': 1 };
$scope.notes = { 'id': 1, 'installation': "" };

You can either use the ng-if, ng-view directives to eliminate, show and hide elements. Something like

<div ng-if="servers.install_id == notes.id" class="panel-note">{{ servers.installation }}</div>
<div ng-if="servers.install_id != notes.id" class="panel-note">{{ servers.install_id }}</div>

In this markup, only one div will be visible at a time.

HOWEVER

If this is to be needed in a lot of places, then you should consider either using a computed variable or a directive.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MrChrisDavidsAuthor Commented:
Indeed it's two variables in a scope - nothing else. Sorry about the mixup there.

I have a dynamic list of servers shown as panels on a view. There are some details on these servers that are common for certain sets and those are the ones that I'd like to render on the view

The details are however accessed from another datasource and the only matches are some IDs from the servers panel that can be matched if they're valid for detail_x kind of.

Let's say, for instance - 20 servers are used for application XYZ which is identified by ID 1. All servers come in with a variable servers.app_id = 1 and I'd then like to write out "XYZ" on the panel instead of the ID.

There's plenty of different IDs that would be replaced, not just the app and notes.

I'll have a look at a directive - see if I can get that working. Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.