Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs ng init不调用ng change函数_Angularjs - Fatal编程技术网

Angularjs ng init不调用ng change函数

Angularjs ng init不调用ng change函数,angularjs,Angularjs,我是angular js的新手,我有一个问题,就像我有一个单选按钮,单击它我想显示一个div,其中包含文本框和重新填充的值 <div class="step-option"> <input type="radio" name="delivery-type" id="mailToMeTab" value="UserAddress" ng-model="UserAddress" ng-init="isShown('UserAddress',

我是angular js的新手,我有一个问题,就像我有一个单选按钮,单击它我想显示一个div,其中包含文本框和重新填充的值

<div class="step-option">
    <input type="radio" name="delivery-type" id="mailToMeTab" value="UserAddress"
        ng-model="UserAddress" 
        ng-init="isShown('UserAddress',userInfo)" 
        ng-click="isShown('UserAddress',userInfo)" 
        ng-checked="true">
    <label for="mailToMeTab" class="textStyle">
    Mail me a Paper Card first <span class="lightcolor">(via U.S. Postal Service)</span>
    </label>
</div>
<div class="col-md-6" id="idUserAddress">
    <h4>Enter your address</h4>
    <input type="text" required placeholder="Your Name" class="form-control" ng-model="cName" />
    <div class="clr10"></div>
        <textarea rows="2" type="text" class="form-control" ng-model="cAddress" placeholder="Street Address"></textarea>
        <div class="clr10"></div>
        <input type="text" class="form-control" placeholder="City" ng-model="cCity">
        <div class="clr10"></div>
        <div class="row">
            <div class="col-md-5">
            <select class="form-control" ng-model="selectedState" required ng-options="s as s.stateName for s in states">
                <option value="">Select State</option>
            </select>
        </div>
        <div class="col-md-7">
            <input type="text" class="form-control" placeholder="Zip" ng-model="cZipCode">
        </div>
    </div>
</div>
<div class="col-md-6" id="idRecipientAddress" @*ng-show="isShown('RecipientAddress')"*@>
    <h4>Enter the recipient's address</h4>
    @if (WebSecurity.IsAuthenticated){
        <input type="text" placeholder="Your Name" class="form-control" typeahead="friend as friend.name +'<br>'+ friend.address +'<br>'+ friend.city for friend in Savedfriends| filter: $viewValue|orderBy:'name'| limitTo:2" ng-model="rName" typeahead-on-select="Filltextboxes(rName)" />
    }
    else{
        <input type="text" placeholder="Your Name" class="form-control" ng-model="rName" />
    }
    <div class="clr10"></div>
        <textarea rows="2" type="text" placeholder="Street Address" class="form-control" ng-model="rAddress"></textarea>
        <div class="clr10"></div>
        <input type="text" class="form-control" placeholder="City" ng-model="rCity">
        <div class="clr10"></div>
        <div class="row">
            <div class="col-md-5">
            <select class="form-control" ng-model="rselectedState" ng-options="s as s.stateName for s in states">
            <option value="">Select State</option>
        </select>
    </div>
    <div class="col-md-7">
        <input type="text" class="form-control" placeholder="Zip" ng-model="rZipCode">
    </div>
</div>
</div>

在ng init上,它确实显示userinfo值,但在页面加载时,它有值,因此它在页面加载时不会显示重新填充的文本框,请帮助我解决这一问题,并建议我是否在某个地方出错。

您确定
userinfo
ng init
触发时有值吗?我看不到任何东西能保证它能做到。我也不明白为什么要将这些事件放在一个看似无关的单选按钮上。是的,我使用调试器看到它,它有一个带有值的对象,但只要ng init调用scope.userinfo值lost@ManishaAgarwal:您可以添加HTML和控制器的代码吗?我必须再次询问:
userInfo
之前是否分配了值,或者在
isShown()
函数运行之后?第一个getUser()函数调用并获取userInfo值,在该isShown()函数调用之后,我使用调试器在页面加载中检查它
cardRepository.getUser().then(function (details) {
    $scope.userInfo = details;
});

 $scope.isShown = function (content, userInfo) {
    debugger;
    //return content === $scope.content;
    if (userInfo.firstName != null && userInfo.lastName != null) {
        $scope.cName = userInfo.firstName + ' ' + userInfo.lastName;
    }
    else {
        $scope.cName = "";
    }

    if (userInfo.address != null) {
        $scope.cAddress = userInfo.address;
    }
    else {
        $scope.cAddress = "";
    }
    if (userInfo.city != null) {
        $scope.cCity = userInfo.city;
    }
    else {
        $scope.cCity = "";
    }
    if (userInfo.zipCode != null) {
        $scope.cZipCode = userInfo.zipCode;
    }
    else {
        $scope.cZipCode = "";
    }
    if (userInfo.state != null) {
        $scope.selectedState = $scope.states[parseInt(userInfo.state) - 1];
    }
    else {
        $scope.selectedState = $scope.states;
    }
    if (content == "UserAndRecipientAddress") {
        $('#idUserAddress').show();
        $('#idRecipientAddress').show();
    }
    else {
        $('#idUserAddress').show();
        $('#idRecipientAddress').hide();
    }

};