javascript - angular.js @local scope property coming as undefined if we initialized as null -


i have made custom angular directive

 <location zipcode="35423" cityname="" statecode=""></location>  

and take

  scope: {                     zipcode: "@",                     cityname: "@",                     statecode: "@"                 }, 

in contoller of directive :

 controller: function ($scope, $filter) { $scope.zipcode = "35423" // here values $scope.cityname = undefined // ?? why? $scope.statecode= undefined // ?? why? } 

i want $scope.cityname = ""

in reality using mvc application

zipcode="@zipcode" cityname="@city" statecode="@statecode" 

and might possible city null

you can set value of scope properties "" if they're undefined so: $scope.cityname = $scope.cityname || "";.

i don't understand why though, since "" , undefined both evaluate false.


Comments

Popular posts from this blog

symfony - InvalidConfigurationException in SecurityExtension.php line 429: No authentication listener registered for firewall "secured_area" -

angular ui router - 10 digest iterations reached in angularjs when using $state.go -

javascript - Handling constructor related functions while testing with mocha and sinon -