我将用户输入传递给控制器函数,但空字符串不声明对象属性。
<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:''}
};
有没有办法在动态传递空字符串时强制创建对象属性?