【发布时间】:2016-05-05 09:59:57
【问题描述】:
我在 Angular js 中使用 ng-repeat, 我有一个添加按钮,我只需要添加一个空对象,这样我就可以将变量初始化为未定义而不是空。
前 我的 HTML
<tr ng-repeat="test in tests">
<td>.....</td>
</tr>
控制器
function getStestItem() {
var testItem = {
ItemID: null,
Test: "",
Description: ""
}
$scope.tests.push(skillItem);
}
$scope.add = function(){getStestItem();}
所以我可以给 as 而不是给空值
function getStestItem() {
var testItem = {
ItemID: null,
Test: undefined,
Description: undefined
}
$scope.tests.push(skillItem);
}
请提出建议。
【问题讨论】:
-
不要设置
undefined。保留该值以表示“尚未设置任何内容”。将其设置为null。 -
你是否尝试给他们空值而不是“未定义”?
-
我尝试给出未定义,我要求未定义的原因是模型范围最初是未定义的。
-
根据定义,未初始化的变量始终是未定义的。 Read more here
-
它与您将 ItemID 的值设置为“null”相同,有关更多详细信息,请查看:stackoverflow.com/questions/5101948/…
标签: javascript angularjs