For example, I pass in a serach object below
In html web page:
<select ng-model="Temp" ng-options="c.abbrZh for c in corpss">
In js.....
$scope.search = function(searchObj){
console.log($scope.Temp.corporationId);
$scope.searchObj.name=$scope.Temp.corporationId;
}
console.log($scope.Temp.corporationId);
There is value here.
But $scope.searchObj.name=$scope.Temp.corporationId;
An error occurs when assigning like this, saying name is not defined. What's going on?
angular.yh.js:12454 TypeError: Cannot set property 'name' of undefined
To solve, how to assign value? ? How to assign the value on the right to the new attribute of the coordinate?
It means you haven’t defined it
searchObj
. At least you can define this object:It’s because your $scope.searchObj has no value assigned, and the result becomes
undefined.name
, which must be an error