更新一些其他功能的功能参数

时间:2016-08-06 15:12:36

标签: javascript angularjs ionic-framework

在这里,我的评论卡在我的应用程序中。我正在制作一个app facebook。其中评论按钮带我到特定的帖子在ionicModal上查看。我可以对那篇文章发表评论。我的问题是我可以评论该帖子我无法立即更新它我必须关闭我的模态并重新打开以查看更新的数据。 这是我的代码

Feed是ng-repeat value

<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上的帖子并更新有关模态的评论

 <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的更新评论它自己哪个我不能 建议一些解决方案 提前致谢

1 个答案:

答案 0 :(得分:0)

希望以下示例能够解决问题。我建议在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();
  };

});