Ng-show / ng-hide从$scope中删除ng-model

ng-show / ng-hide removes ng-model from $scope

本文关键字:删除 ng-model scope ng-hide Ng-show      更新时间:2023-09-26
  <div ng-show="!showTagging" class="form-group">
              <div class="form-group">
                <div ng-show="!showPreview"> Add a photo of you enjoying a specific whiskey or an image inspired by one!</div>
                <hr></hr>
  //when file is uploaded below, it sets $scope.post.picturePreCrop
                <label id="upload" required ng-model="post.picturePreCrop" ngf-pattern="image/*" ngf-select="droppedFile()" accept="image/*" ngf-accept="'image/*'" ngf-pattern="'.jpeg,.jpg,.png,.bmp'" ngf-max-size="8MB" ngf-max-files="1" ngf-fix-orientation="true">
                      <div class="add-link"><i class="fa fa-camera"></i><a class="underlined"> Add or Take a Photo:</a></label></div>
              <div></div>
              <ng-croppie ng-if="post.picturePreCrop" src="post.picturePreCrop | ngfDataUrl" ng-model='post.pictureUrl' update='onUpdate' boundry="{w: 200, h: 200}" viewport="{w: 200, h: 200}" mousezoom="true" zoom="true" type="square">
              </ng-croppie>
              <img ng-if="!post.picturePreCrop" class="prof-photo" ng-src="{{post.picture || 'https://placehold.it/200x200'}}">
            </div>
//once picture is cropped, it sets $scope.post.pictureUrl
            <div class="btn btn-lg btn-block btn-success" ng-disabled="post.picturePreCrop === undefined" ng-click="showTagging = true"> Next </div>

//when the next button above is hit, $scope.post.pictureUrl is removed, but post.picturePreCrop still persist.
</div>

我正在使用ng-croppie指令。当我隐藏包含ng-croppie的div时,我的裁剪url将在$scope中消失。

pictureUrl:"data:image/png;base64,iVBORw0KGgoAAAAN...

一旦ng-show被调用,to:

pictureUrl:"data:,"

如果取消隐藏div, pictureUrl将返回到预期的位置。

我如何使这个pictureUrl属性持续存在,即使它是隐藏的?

我知道ng-if会从dom中删除元素,但这似乎出乎ng-show的意料。

您的ng-show指令放置在您的ng-croppie控件的父DIV上。ng-show切换HTML控件的显示,这意味着当ng-show条件表达式不满足时,您的整个div(和它的内容)将被隐藏,包括DIV子。你需要把你的ng-croppie移出这个DIV或地方你的ng-show指令在其他地方不包括ng-croppie控件。