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
Post a Comment