angular.js - An error occurred when adding a new attribute assignment in angularjs. What happened?
仅有的幸福
仅有的幸福 2017-05-15 17:02:14
0
2
560

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?

仅有的幸福
仅有的幸福

reply all(2)
过去多啦不再A梦

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;
};
Ty80

It’s because your $scope.searchObj has no value assigned, and the result becomes undefined.name, which must be an error

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template