无法读取未定义错误Angularjs的属性

时间:2014-07-11 23:06:37

标签: html angularjs

我是angularjs和html的新手,我收到了这个错误,"无法读取属性' Dateofbirth'未定义的错误"。我做了一点调整,发现由于某种原因,我的api调用被忽略了。这就是代码的样子......

profile.controller("profileController", ["$scope","$resource", function($scope, $resource) {

// get the user id
$scope.userid = sessionStorage["cerestiuserid"];

// json we get from server
$scope.apicall = sessionStorage["cerestihome"];     

//grabs the user we want
if(typeof sessionStorage["infos"] == "undefined") {

    $scope.userResource = $resource($scope.apicall + "/api/userprofile/", {Userid:$scope.userid}, {'get':{method: 'POST'}});

    //fetch JSON        
THIS PART OF CODE IS SKIPPED FOR SOME REASON--->    $scope.userResource.get(function(result, putResponseHeaders) {

        // get the name field
        $scope.infos = result;
        sessionStorage["infos"] = JSON.stringify(result);

    });

} else {

    $scope.infos = JSON.parse(sessionStorage["infos"]);
}

// show/hide helper function
$scope.hide = function() {

        var DOB = JSON.stringify($scope.infos.Dateofbirth.Valid);
        var lang_size = $scope.infos.Languages.length;
        var Ethn = JSON.stringify($scope.infos.Ethnicity.Valid);


        // check if the JSONS are empty
        if ( DOB === 'false' & Ethn === 'false' & lang_size === 0) {
            return 'true';
        }
        else {
            // one of the JSON's have elements
            return 'false';
        }


        // check if the JSONS are empty
        if ( DOB === 'false' & Ethn === 'false' & lang_size === 0) {
            return 'true';
        }

        // one of the JSON's have elements
        return 'false';

};  

}]); 

这是html代码,我调用该函数并使用JSON ...

<div class="dl-horizontal" style="margin-top:10px">
        <ul class="list-group">
        <li class="list-group-item">
                <div ng-show="infos.Dateofbirth.Valid == true">
                    <dt> Date of Birth </dt>
                    <dd> {{infos.Dateofbirth.Date}} </dd>
                </div>

                <div ng-show="infos.Ethnicity.Valid == true">
                    <dt> Ethnicity </dt>
                    <dd> {{infos.Ethnicity.String}} </dd>
                </div>

                <div ng-hide="infos.Languages.length == 0"> 
                    <dt> Language </dt>
                    <dd>
                        <div ng-repeat="info in infos.Languages">
                            <div>{{info}}&nbsp;</div>
                        </div>
                    </dd>
                </div>

            <div ng-show="hide()">
                <p>No information to show</p>
            </div>
        </li>
        </ul>
        </div>
    </div>
    </div>
    </div>
    </div>

先谢谢

0 个答案:

没有答案