Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
referencing objects with a lot of fields
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tamas Herman  
View profile  
 More options Mar 26 2012, 3:36 am
From: Tamas Herman <hermanta...@gmail.com>
Date: Mon, 26 Mar 2012 15:36:54 +0800
Local: Mon, Mar 26 2012 3:36 am
Subject: referencing objects with a lot of fields
guys,  

im trying to display an object with 10-20 attributes.
some of the values of these attributes are also similarly big objects or arrays of such objects.

i would like to omit prefixing each field name with the sub-object's name.
similarly as knockoutjs does in their example on the homepage:

<p data-bind="with: chosenTicket">
  xxx <b data-bind="text: name"></b>

pascal had a similar construct which was also called "with"

so how can i achieve something like this in angular:

$scope.obj = {
  f1: 123123
  f2: "asdasd"
  …
  f13: {
    sub1: true
    sub2: 555
    …
    sub20: null
  }
  f18: [ {...}, {…}, ... ]

}

<p with="obj">
  <h3>{{f1}}</h3>
  <p>{{f2}}<p>
  ...
  <div with="f13">
    Done: {{sub1}}
    Size: {{sub2}}
    …
    <span ng-show="sub20">OK</span>
  </div>
  ...
</p>

instead of the current

<p>
  <h3>{{obj.f1}}</h3>
  <p>{{obj.f2}}<p>
  ...
  <div with="obj.f13">
    Done: {{obj.f13.sub1}}
    Size: {{obj.f13.sub2}}
    …
    <span ng-show="obj.f13.sub20">OK</span>
  </div>
  ...
</p>

i was trying to hack it like this:

<script type="text/ng-template" id="/embedded.html">
  <div>
    Done: {{sub1}}
    Size: {{sub2}}
    …
    <span ng-show="sub20">OK</span>
  </div>

</script>

<div ng-inculde src="'/embedded.html'" scope="extend($new, obj.f13)"></div>

but it didnt do anything.
didn't throw any error either which made me feel good about it actually :)

i have the impression that i really read the full docs…
would these sections make me understand whats going on?
http://docs-next.angularjs.org/api/angular.module.ng.$rootScope.Scope
http://docs-next.angularjs.org/api/angular.module.ng.$compileProvider...

is it silly for some reason what i want?
pls, help.

--  
  tom


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Bacon Darwin  
View profile  
 More options Mar 26 2012, 4:14 am
From: Peter Bacon Darwin <p...@bacondarwin.com>
Date: Mon, 26 Mar 2012 09:14:06 +0100
Local: Mon, Mar 26 2012 4:14 am
Subject: Re: [angular.js] referencing objects with a lot of fields

Hi Tamas
You can get this effect by extending the scope inside a controller.  For
each new controller a new scope is created that exists only where that
controller exists so you are free to hack it to bits as long as you are
sure that is what you want to do.
See this fiddle: http://jsfiddle.net/86kuc/
Pete

On 26 March 2012 08:36, Tamas Herman <hermanta...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vojta Jína  
View profile  
 More options Mar 27 2012, 12:47 am
From: Vojta Jína <vojta.j...@gmail.com>
Date: Mon, 26 Mar 2012 21:47:08 -0700
Local: Tues, Mar 27 2012 12:47 am
Subject: Re: [angular.js] referencing objects with a lot of fields
Pete, thank you so much for answering all the questions here on mailing list.
We really appreciate it.

Would you like to have an AngularJS t-shirt ?
Fill in this form
https://docs.google.com/spreadsheet/viewform?formkey=dGlWVFNocm9hWFF0...
and we will send you some...

V.

On Mon, Mar 26, 2012 at 1:14 AM, Peter Bacon Darwin


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Suller Andras  
View profile  
 More options Mar 27 2012, 4:03 am
From: Suller Andras <suller.and...@gmail.com>
Date: Tue, 27 Mar 2012 15:03:38 +0700
Local: Tues, Mar 27 2012 4:03 am
Subject: Re: [angular.js] referencing objects with a lot of fields
On Mon, Mar 26, 2012 at 3:14 PM, Peter Bacon Darwin

<p...@bacondarwin.com> wrote:
> Hi Tamas
> You can get this effect by extending the scope inside a controller.  For
> each new controller a new scope is created that exists only where that
> controller exists so you are free to hack it to bits as long as you are sure
> that is what you want to do.
> See this fiddle: http://jsfiddle.net/86kuc/
> Pete

Interesting approach. But (of course) it breaks the 2way databinding,
since the attributes will be copied to the new scope. Is there any
chance to achieve the same effect without making new copies of the
data?
Or try to keep the two copies in sync with a $watch for every
attribute? It sounds too hackish.

Andras


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Bacon Darwin  
View profile  
 More options Mar 27 2012, 4:36 am
From: Peter Bacon Darwin <p...@bacondarwin.com>
Date: Tue, 27 Mar 2012 09:36:11 +0100
Local: Tues, Mar 27 2012 4:36 am
Subject: Re: [angular.js] referencing objects with a lot of fields

Copies are only made of primitive types.  If you are willing to accept one
level of indirection then you get references to objects.
See this version: http://jsfiddle.net/86kuc/1/
Pete

On 27 March 2012 09:03, Suller Andras <suller.and...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Bacon Darwin  
View profile  
 More options Mar 27 2012, 4:36 am
From: Peter Bacon Darwin <p...@bacondarwin.com>
Date: Tue, 27 Mar 2012 09:36:40 +0100
Local: Tues, Mar 27 2012 4:36 am
Subject: Re: [angular.js] referencing objects with a lot of fields

Awesome and wholly undeserved - but I'll take one anyway!
Thanks
Pete

On 27 March 2012 05:47, Vojta Jína <vojta.j...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Igor Minar  
View profile  
 More options Mar 29 2012, 2:43 am
From: Igor Minar <i...@angularjs.org>
Date: Wed, 28 Mar 2012 23:43:26 -0700
Local: Thurs, Mar 29 2012 2:43 am
Subject: Re: [angular.js] referencing objects with a lot of fields

On Tue, Mar 27, 2012 at 1:03 AM, Suller Andras <suller.and...@gmail.com>wrote:

There isn't another way.

> Or try to keep the two copies in sync with a $watch for every
> attribute? It sounds too hackish.

I wouldn't recommend that.

What's your objective? Saving key strokes or something else?

I'm all for saving key strokes but in this case, it would add yet another
scoping dimension to the templating syntax which might make it hard to
follow.

/i


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »