如,我下面傳入一個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;
};