Scottie
Scottie

Reputation: 11308

Better way to debug AngularJS?

So I spent approx 4 hours yesterday trying to track down an error in AngularJS.

What I finally discovered was that my directive has an optional parameter, and I had a section of code that was trying to assign a value to this parameter which was throwing an extremely un-useful angular error.

The error is something like:

Error: [$compile:nonassign] Expression 'undefined' used with directive 'testDirective' is non-assignable!
http://errors.angularjs.org/1.3.7/$compile/nonassign?p0=undefined&p1=testDirective
minErr/<@https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.7/angular.js:63:12
nodeLinkFn/</parentSet<@https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.7/angular.js:7652:1
parentValueWatch@https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.7/angular.js:7665:23
regularInterceptedExpression@https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.7/angular.js:12831:16
$RootScopeProvider/this.$get</Scope.prototype.$digest@https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.7/angular.js:14215:34
$RootScopeProvider/this.$get</Scope.prototype.$apply@https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.7/angular.js:14486:13
ngEventHandler/<@https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.7/angular.js:22945:17
createEventHandler/eventHandler@https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.7/angular.js:3009:9

As you can see, it tells me the directive that is causing the problem, but nothing about what specific line # or statement caused it.

Is there a better way to determine which line caused this error without commenting out code and trial and error?

I've created a plunker that illustrates the issue:

http://plnkr.co/edit/zxPegBlAxUKdewdmA6Oc?p=preview

Upvotes: 1

Views: 441

Answers (1)

Mathew Berg
Mathew Berg

Reputation: 28750

You cannot get the exact line number it happens on, but if you go to the error link you have there:

http://errors.angularjs.org/1.3.7/$compile/nonassign?p0=undefined&p1=testDirective

It might give some insight into what it could be. Seems it does mention that you are using it incorrectly (the third error says the bind wasn't provided)

Upvotes: 1

Related Questions