我将用户输入传递给控制器函数,但空字符串不声明对象属性。ng-model未定义为空字符串?
<form>
<input type="text" ng-model="data.location" />
<input type="text" ng-model="data.radius" />
<button type="button" ng-click="getSearch(data)">Search</button>
</form>
$scope.getSearch = function(data) {
console.log(data);
//undefined
//...but what if I want {location:'', radius:''}
};
有没有办法强制空中传递空字符串时创建的对象属性?
访问当然,但这是唯一的方法吗?没有办法强制它在飞行中? –
@DanKanze没有其他对象将被初始化,只有当你编辑文本框 –
ng-init = {data:{location:'',radius:''}“会做的伎俩,但它在控制器 – Mephiztopheles