Skip to content
This repository has been archived by the owner on Aug 24, 2017. It is now read-only.

Suggestion: When data model key doesn't exist, add it automatically (0.3.1) #38

Open
WhatFreshHellIsThis opened this issue May 15, 2014 · 0 comments

Comments

@WhatFreshHellIsThis
Copy link

I would like to see a feature added where the component will create a key on the data model if it doesn't already exist:

I am using this with a rest service backed by a document db. So when my record comes to the page there is a possibility that the key I've indicated as my data model for the tags simply doesn't exist.

For example, let's say I have a 'user' object in the scope and it never had any tags added to it, so the model would be 'user.tags' however that key doesn't exist yet which is natural and normal with a document database.

This results in an exception in 0.3.1 (non templates version):

 TypeError: Cannot set property 'length' of undefined
  at Object.fn (http://localhost:3000/vendor/angular-tags-0.3.1.js:455:41)
  at Scope.$digest (http://localhost:3000/vendor/angular.js:12251:29)
  at Scope.$apply (http://localhost:3000/vendor/angular.js:12516:24)
  at http://localhost:3000/vendor/angular.js:14023:36
  at completeOutstandingRequest (http://localhost:3000/vendor/angular.js:4300:10)
  at http://localhost:3000/vendor/angular.js:4601:7 

Specifically this block of code in the "watchTags" function:

...
      }
               else {
                 scope.model.length = 0;//<---- HERE IS THE ERROR
                 for (i = 0; i < value.length; i++) {
                   scope.model.push(value[i]);
                 }
               }
               watchModel();
...

Ideally I think, if a user specifies

<tags model="user.tags" 

If user exists on the scope then it should add the user.tags key automatically like other components do.

In the mean time I'm working around it by intercepting the record coming from the server and adding the empty key if it doesn't exist, however this is not ideal with a document database system.

@WhatFreshHellIsThis WhatFreshHellIsThis changed the title Problem when data model key doesn't exist (0.3.1) Suggestion: When data model key doesn't exist, add it automatically (0.3.1) May 15, 2014
@boneskull boneskull self-assigned this May 18, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants