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?
过去多啦不再A梦2017-05-15 17:04:14
It means you haven’t defined itsearchObj
. At least you can define this object:
$scope.searchObj = {};
$scope.search = function(searchObj){
console.log($scope.Temp.corporationId);
$scope.searchObj.name=$scope.Temp.corporationId;
};
PHP中文网2017-05-15 17:04:14
It’s because your $scope.searchObj has no value assigned, and the result becomes undefined.name
, which must be an error