更新其他函数的函数参数

update function parameters on some other function

本文关键字:函数 参数 更新 其他      更新时间:2023-09-26

在这里,我被困在我的应用程序中,留下了评论。我正在制作一个类似facebook的应用程序。在ionicModal上可以查看带我到特定帖子的评论按钮。我可以对那篇帖子发表评论。我的问题是,我可以在那篇帖子上发表评论,我不能立即更新它,因为我必须关闭我的模态并重新打开以查看更新的数据。这是我的代码

进料为ng重复值

<div ng-click="commentModalOpen(feed)">

模式代码是

$ionicModal.fromTemplateUrl('templates/comment.html', {
      scope: $scope,
      animation: 'slide-in-up'
        }).then(function(modal) {
          $scope.commentModal = modal;
        });
        $scope.commentModalOpen = function(feed) {
          $scope.commentModal.show();
          $scope.feed = feed;
        };

其中$scope.feed向我展示了我在ionicModal上的帖子,并更新了对modal 的评论

 <textarea ng-model="obj.postcomment" id="postcomment" placeholder="Your Comment" autofocus="true"></textarea>
   <div ng-click='btn_add(feed.PostId,obj);' >Post Comment</div>

btn_add添加了我的评论,尽管我想在ionicModal it self上显示我更新的评论,但我无法提出一些解决方案提前感谢

希望下面的例子能澄清问题。我建议在play.ionic.io 上测试一下

html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <link href="https://code.ionicframework.com/1.0.0/css/ionic.min.css" rel="stylesheet">
    <script src="https://code.ionicframework.com/1.0.0/js/ionic.bundle.js"></script>
  </head>
  <body ng-app="app">
    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">Awesome App</h1>
      </ion-header-bar>
      <ion-content class="padding" ng-controller="MainCtr">
        <button class="button button-assertive" ng-click="openModal()">I'm a button</button>
      </ion-content>
    </ion-pane>
    <script id="my-modal.html" type="text/ng-template">
  <ion-modal-view>
    <ion-header-bar>
      <h1 class="title">My Modal title</h1>
    </ion-header-bar>
    <ion-content>
      <div ng-repeat="obj in feed">
        <div>{{obj.text}}</div>
        <div> 
          <textarea ng-model="obj.postcomment" id="postcomment" placeholder="Your Comment" autofocus="true"></textarea>
          <button ng-click="obj.text = obj.postcomment">post</button>
        </div>
      </div>
    </ion-content>
  </ion-modal-view>
</script>
  </body>
</html>

js

angular.module('app', ['ionic']).controller('MainCtr', function($scope, $ionicModal) {
  $scope.feed = [
      {text:'fb is dumb ~la', postcomment:''}, 
      {text:'no it''s not lol', postcomment:''}];
  $ionicModal.fromTemplateUrl('my-modal.html', {
    scope: $scope,
    animation: 'slide-in-up'
  }).then(function(modal) {
    $scope.modal = modal;
  });
  $scope.openModal = function() {
    $scope.modal.show();
  };
});