2

I have started a new AngularJS project - and this time something strange is happening. Whenever I get an error in the browser's console, it references to the angular.js file. I don't know what's different with this app from all my others - maybe the AngularJS version (1.6.4). Or the fact that I'm using controllerAs syntax?

For example - if I try the following in my main controller:

vm.notdefined.somevalue = "this should give an error";

I don't get a console error with the line of code in my controller, but with a line in angular.js:

angular.js:14525 TypeError: Cannot set property 'somevalue' of undefined(…) ""

It would be ok for me if I could trace back the error from the stack trace - but also the stack trace does not contain any information on the position of the error in my project.

enter image description here

0

2 Answers 2

1

The error is thrown where it appears. vm.notdefined.somevalue is a part of ngControllerinstance. In the moment your controller get parsed the error is thrown. This happends inside AngularJS kernel logics. You could check the stack trace for debugging. It should lead you to your controller function. You could also use breakpoints on your code e.g. by using chrome debugger. All in all this will lead you to the origin of this error.

For more information about debugging please check this answer: How can I get more stacktrace in AngularJS

The error message is quite clear: vm.notdefined is undefined. Try:

vm = this;
vm.notdefined = {
   somevalue: "this should give an error"
}
Sign up to request clarification or add additional context in comments.

5 Comments

I create this error intentionally! I want to demonstrate, that the error is refered to a line in angular.js, instead of the correct position in my controller file.
@Gerfried it is correct, that the error is thrown in angular.js file because vm is an instance of angular-controller. It is the correct "position/line" of code where the error is thrown. What's wrong with it? And what is your question so?
It's difficult to debug errors. I also tried with $scope instead of vm - same behaviour. This is new to me - in my other projects the error shows up in the controller.
@Gerfried This is not a problem at all. Check the stack trace for debugging. What is your question so? What kind of answer do you expect or what kind of answer would you mark as right?
Ok, I understand - but in the stack trace there is no information on my controller file as well. I will add it to my question
0

Shame on me - I missed to click on the three dots to expand the error message: enter image description here

Not sure why I have to do this sometimes and other times I get the error stack in the immediate stack.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.