Heim > Fragen und Antworten > Hauptteil
如,我下面传入一个serach对象
在html网页中:
<select ng-model="Temp" ng-options="c.abbrZh for c in corpss">
在js中.....
$scope.search = function(searchObj){
console.log($scope.Temp.corporationId);
$scope.searchObj.name=$scope.Temp.corporationId;
}
console.log($scope.Temp.corporationId);
这里是有值的。
但是$scope.searchObj.name=$scope.Temp.corporationId;
这样赋值就发生错误,说name没有定义,怎么回事呢?
angular.yh.js:12454 TypeError: Cannot set property 'name' of undefined
求解,如何赋值??如何把右边的赋值给坐标的新的属性呢?
过去多啦不再A梦2017-05-15 17:04:14
说明你没定义searchObj
,好歹你也把这个对象定义一下呗:
$scope.searchObj = {};
$scope.search = function(searchObj){
console.log($scope.Temp.corporationId);
$scope.searchObj.name=$scope.Temp.corporationId;
};