I'm really just getting started in earnest with Angular.js and one of the first things I noticed is that it doesn't often throw errors if something isn't found.
我只是认真地从角度开始。我首先注意到的一件事是,如果找不到什么东西,它通常不会抛出错误。
In a trivial example, if something_undefined
is undefined:
在一个简单的示例中,如果某个东西没有定义:
<p>{{something_undefined}}</p>
this will fail silently with:
这将无声地失败:
<p></p>
In an example with a $resource
, if I made a typo like {{member.frist_name}}
I'd quite like Angular to tell me that there was no such attribute frist_name
on member
.
在一个具有$resource的示例中,如果我做了一个类型为{{member.frist_name}}的类型,我就会非常喜欢角度告诉我,成员中没有这样的属性frist_name。
2 个解决方案
#1
2
Just for testing purposes you can display an error message instead of empty string by
仅为了测试目的,您可以显示一条错误消息,而不是空字符串。
<p> {{ something_undefined || 'Not Found !!!' }} </p>
#2
1
This does not aim to be an answer but a related suggestion, coming from my experience and referring also to the other answer, which is indeed useful.
这不是一个答案,而是一个相关的建议,来自于我的经验,也参考了另一个答案,这确实是有用的。
When you start having this kind of problems while developing with angular, write down some tests about it! This way you will keep your code free from extra debugging statements, you will understand better the framework, and you will leave some regression tests after the process. A win on all sides.
当你开始遇到这种问题的时候,当你有角的时候,写下一些关于它的测试!通过这种方式,您将使代码不受额外的调试语句的影响,您将更好地理解框架,并且您将在过程之后留下一些回归测试。各方面的胜利。
#1
2
Just for testing purposes you can display an error message instead of empty string by
仅为了测试目的,您可以显示一条错误消息,而不是空字符串。
<p> {{ something_undefined || 'Not Found !!!' }} </p>
#2
1
This does not aim to be an answer but a related suggestion, coming from my experience and referring also to the other answer, which is indeed useful.
这不是一个答案,而是一个相关的建议,来自于我的经验,也参考了另一个答案,这确实是有用的。
When you start having this kind of problems while developing with angular, write down some tests about it! This way you will keep your code free from extra debugging statements, you will understand better the framework, and you will leave some regression tests after the process. A win on all sides.
当你开始遇到这种问题的时候,当你有角的时候,写下一些关于它的测试!通过这种方式,您将使代码不受额外的调试语句的影响,您将更好地理解框架,并且您将在过程之后留下一些回归测试。各方面的胜利。