javascript - How to resolve TypeError: Cannot convert undefined or null to object at Function.keys (<anonymous>) -


i trying hide field. when user cliks on glyphicon-eye-open, display glyphicon-eye-close , considering condition true. if condition true pushing value array.

i using below function, have 2 roles actor , singer. both similar fields same model name. displaying values based on role.

i able push value array actor. if try same singer showing below error.

even tried different model name still getting same error.

 typeerror: cannot convert undefined or null object         @ function.keys (<anonymous>)         @ $$childscopeclass.manageprofilecontroller.$scope.pushrolefield (manageprofile.controller.js:214)         @ angular.js:10773         @ angular.js:18981         @ $$childscopeclass.$eval (angular.js:12608)         @ $$childscopeclass.$apply (angular.js:12706)         @ htmllabelelement.<anonymous> (angular.js:18980)         @ htmllabelelement.dispatch (jquery-2.0.3.min.js:5)         @ htmllabelelement.y.handle (jquery-2.0.3.min.js:5) 

my html :

<div class="wrap"> <div class="panel-body newpanelbody" ng-if="displaysingerinfo && !displayactorinfo">  <div class="newwrap">             <label for="qual"  class="first-heading">about you*<span class="styleatr">not more 160 characters</span></label>              <textarea rows="4" cols="10" id="qual" class="textarea1" placeholder="say " ng-model="model.aboutyou">             </textarea>           </div>                  <label ng-class="{'glyphicon glyphicon-eye-close': allowrole.saboutyou, 'glyphicon glyphicon-eye-open': !allowrole.saboutyou}" ng-click="pushrolefield(allowrole.saboutyou = allowrole.saboutyou?false:true)"><input class="eyecheck1" type="checkbox" ng-model="allowrole.saboutyou" ng-hide="allowrole.saboutyou || !allowrole.saboutyou"/></label>                                          </div> </div>  <div class="panel-body newpanelbody" ng-if="displayactorinfo && !displaysingerinfo">  <div class="newwrap">             <label for="qual"  class="first-heading">about you*<span class="styleatr">not more 160 characters</span></label>              <textarea rows="4" cols="10" id="qual" class="textarea1" placeholder="say " ng-model="model.aboutyou">             </textarea>           </div>                  <label ng-class="{'glyphicon glyphicon-eye-close': allowrole.saboutyou, 'glyphicon glyphicon-eye-open': !allowrole.saboutyou}" ng-click="pushrolefield(allowrole.saboutyou = allowrole.saboutyou?false:true)"><input class="eyecheck1" type="checkbox" ng-model="allowrole.saboutyou" ng-hide="allowrole.saboutyou || !allowrole.saboutyou"/></label>                                          </div> </div> </div> 

my controller :

$scope.rolehide = {         aboutyou: 'aboutyou',         saboutyou: 'saboutyou     };      $scope.allowrole = {         aboutyou: false,         saboutyou: false     };      $scope.rolehiddenfields = [];      $scope.pushrolefield = function(allow){         debugger;         console.log(allow);         $scope.rolehiddenfields = [];         var users = {},              allows = $scope.allowrole;       object.keys(allows).foreach(function(key){         allows[key] ? users[key] = $scope.rolehide[key] : null;       });       $scope.rolehiddenfields.push(users);     };  

near end of js file use one-line if condition, null. replace null empty object or empty array.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -