Expression 'undefined' used with directive 'jsonEdit' is non-assignable!

421 views
Skip to first unread message

Jonathan Matthew Beck

unread,
Jun 30, 2014, 3:23:59 PM6/30/14
to ang...@googlegroups.com
Here is the plunker: http://plnkr.co/edit/4nPX4Z

The json directive will send a message to the jsonEdit directive, which will load a template with a new model displayed.

I don't know why it isn't working.  Once I get the message there I keep encountering this error: Expression 'undefined' used with directive 'jsonEdit' is non-assignable!


Jonathan Matthew Beck

unread,
Jul 1, 2014, 8:10:20 AM7/1/14
to ang...@googlegroups.com
Ok I think I've got it, and please correct me if I am wrong.  (No, really, I want to learn this stuff).

The automagical things Angular does with variables and scopes is throwing me a bit, coming from C# where I "own" the variables.  In certain context's Angular "owns" the variables and that's why I get errors.

What I think it boils down to is: If I want to create or add a variable to a scope, don't do it in the directive's html tag or in the scope: {} declaration.  Just declare the variable in the code as:

scope.myVar = 0;     - this is my var, and yes it is in the scope.

not

<mydir myVar="0"></myDir>   --  Angular says, "nono!! That's MY var now."

or

return {
  restrict:'E',
  scope: {
     myVar: "0"              --  not your var anymore, Toto!
  },
...
}


--
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/pgk1I8T-5lc/unsubscribe.
To unsubscribe from this group and all its topics, 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.

Jonathan Matthew Beck

unread,
Jul 1, 2014, 8:16:04 AM7/1/14
to ang...@googlegroups.com
...or better yet declare vars inside an object to prevent the dreaded (Halloween voice)  "scope overlap!"

scope.myContainer = {};

scope.myContainer.myScopeSafeVar = 0;
Reply all
Reply to author
Forward
0 new messages