Call out undefined bindings?

94 views
Skip to first unread message

jsawyer

unread,
Sep 30, 2011, 12:19:39 PM9/30/11
to AngularJS
Is there a way for AngularJS to actively inform me of what in another
language would be a compile-time error?

Let's say I try to bind to "myValue", but I type "{{myValu}}" instead.
It would seem valuable to me if Angular would generate an error when
it encountered a value of "undefined" rather than ignoring it. To
avoid errors like this, I'd need to explicitly declare scoped
variables (e.g. "this.myValue = null"). To be clear, "null" would be
handled as it is today; I'm specifically targetting "undefined"
errors.

This would also apply to expressions, like "{{a.b.c}}"; if b were
undefined, I would also expect an error.

Perhaps this could be a settable "strict mode" setting, if there are
situations where this is undesirable. In addition, perhaps there would
be a need to override this behavior on a binding-by-binding basis, in
cases where, due to circumstances beyond my control, the expression
may be undefined at times. Maybe use a slightly different syntax, like
"{{{ ... }}}" for strict vs. non-strict binding? That's just an
suggestion, I'm sure you can come up with much better syntax. :-)

The goal is one more justification for not having to test the view.

js

Mårten Dolk

unread,
Oct 1, 2011, 3:48:04 AM10/1/11
to ang...@googlegroups.com
This has been discussed before:
http://groups.google.com/group/angular/browse_thread/thread/a3214501fc21eee9?hl=en

Don't know what come out of it though, think it dropped off the radar?

/Mårten

2011/9/30 jsawyer <jonrs...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "AngularJS" 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.
>
>

Vojta Jina

unread,
Oct 2, 2011, 10:41:12 PM10/2/11
to ang...@googlegroups.com
Well, many people find it useful, that you don't have to define stuff... I think the solution might be to log these cases - so during development, you can inject logger that throws exception and in production just ignore...

V.

Igor Minar

unread,
Oct 3, 2011, 11:09:36 AM10/3/11
to ang...@googlegroups.com
That thread discussed only writing into (and initializing) unknown models (variables). The long-term plan is to disallow assignments (aside from 2way data binding) in the view completely, so this is not going to be an issue.

When it comes to reading, we strongly believe that read-only autovivification[1] is a good thing because it allows you to write concise templates without if (foo != null) checks.

As always there are are tradeoffs that each feature brings, and in this case there is a possibility to create bad bindings due to typos in the template. In practice we don't find this to be a big issue and since we preach that apps should be built with good test suite, the end-to-end tests should verify that your bindings are properly set up.

We could create log messages when a undefined binding is being evaluated, but I think that because this behavior is a feature and not a bug this logging would be a very noisy and for that reason useless feature.

/i

Reply all
Reply to author
Forward
0 new messages