2016-05-25 11 views
0

理由はわかりませんが、index.htmlは更新したくありません。 私はコードで私の問題を表示しようとします:あなたが見ることができるように私の配列で変更を加えることができる2つのボタンがありますAngularJSの別のコントローラからの変更後にリストビューが更新されない

// Index.html part:

<ion-view> 
    <ion-content has-header="true" has-subheader="true"> 
     <ion-list can-swipe="true"> 
     <ion-item class="item item-avatar item-remove-animate" ng-repeat="contact in contactIndexCtrl.contacts | filter: contactIndexCtrl.search track by contact.id" 
      ui-sref="root.contact-detail(::{ id: contact.id })"> 
       <img ng-src="./img/{{::contact.pic}}"> 
        <h2>{{::contact.firstName }} {{ ::contact.lastName }}</h2> 
      <ion-card-content> 
       <h2>{{::contact.title}}</h2> 
       <p ng-bind-html="::contact.department"></p> 
      </ion-card-content> 
      <ion-option-button ng-click="contactIndexCtrl.edit(contact)" class="button-light icon ion-edit"> Edit</ion-option-button> 
      <ion-option-button ng-click="contactIndexCtrl.remove($event, contact)" class="button-assertive icon ion-trash-a" > Delete</ion-option-button> 
     </ion-item> 
     </ion-list> 
    </ion-content> 
</ion-view> 

。削除のために、私は私のアイテムを表示するのと同じコントローラを使用しています。ここではすべてがうまくいき、ボタンを押した後に更新されるインデックスビューのリストです。 localStorageに連絡先の

<ion-modal-view> 
    <ion-header-bar class="bar bar-header bar-positive"> 
    <h1 class="title">New Contact</h1> 
    <button class="button button-clear button-primary" ng-click="modal.hide()">Cancel</button> 
    </ion-header-bar> 
    <ion-content ng-controller="ContactEditController as contactEditCtrl" class="padding"> 
    <div class="list"> 
     <label class="item item-input"> 
       <span class="input-label">First Name</span> 
       <input ng-model="editingItem.firstName" type="text"> 
      </label> 
     <label class="item item-input"> 
       <span class="input-label">Last Name</span> 
       <input ng-model="editingItem.lastName" type="text"> 
      </label> 
     <label class="item item-input"> 
       <span class="input-label">Email</span> 
       <input ng-model="editingItem.email" type="text"> 
      </label> 
     <div class="list"> 
     <label class="item item-input item-select"> 
    <div class="input-label"> 
     Select Manager 
    </div> 
    <select name="managerSelection" ng-model="editingItem.managerId"> 
    <option ng-repeat="manager in contactEditCtrl.contacts" value="{{manager.id}}">{{manager.firstName + " " + manager.lastName}}</option> 
    </select> 
    </label> 
     </div> 
     <button class="button button-full button-positive" ng-click="save(editingItem)">Save Edits</button> 
    </div> 
    </ion-content> 
</ion-modal-view> 

contactsServicearray

// IndexController part:

import contactEditTemplate from "../contact-edit/contact-edit.html"; 
export default class ContactIndexController { 

    constructor($scope, $state, $q, $log, $ionicModal, $ionicListDelegate, contactsService) { 
     'ngInject'; 
     let vm = this; 
     vm.edit = edit; 
     vm.remove = remove; 

     contactsService.findAll().then((contacts) => { 
      vm.contacts = contacts; 
     }); 

     $scope.modal = $ionicModal.fromTemplate(contactEditTemplate, { 
      scope: $scope, 
      animation: 'slide-in-up' 
     }); 

     $scope.$on('modal.hidden', function() { 
      contactsService.findAll().then(angular.bind(this, function (response) { 
      vm.contacts = response; 
     }); 
     function edit(item) { 
      $scope.editingItem = item; 
      $ionicListDelegate.closeOptionButtons(); 
      $scope.modal.show(); 
     } 

     function remove(event, item) { 
      contactsService.remove(item); 
     } 

contact-edit.html

問題は私の項目を編集している

// Update method from service

update(item) { 
    this.$storage.contacts.some(function (contact) { 
     if (parseInt(contact.id) === parseInt(item.id)) { 
      Object.assign(contact, item); 
      return true; 
     } 
    }); 
    return this.$q.when(this.$storage.contacts); 
} 

// And functions from EditCtrl:

$scope.save = function (item) { 
     $log.info($scope.editingItem); 
     $scope.modal.hide(); 
     contactsService.update($scope.editingItem).then((contacts) => { 
      vm.contacts = contacts; 
     }.bind(this)); 
    }; 

私は同じことしかページの更新後に更新するすべての連絡先を持つメインビューを行います。また、編集後にモデルウィンドウを開くと、連絡先に値が更新されます。私のコードの問題は何ですか? ありがとうございます!

+0

この投稿はあなたに役立つと思います。http://stackoverflow.com/questions/21919962/share-data-between-angularjs-controllers完全な例がなければ、何が間違っているかを確かめるのは難しいですが、一般的にこれらの問題はスコープ/プロトタイプの継承によるものです。 – Brian

+0

@brianslattery私は自分の質問を更新しました。 – user3818229

答えて

1

問題があります「1回限りのバインディング」 の直前に<h2>{{::contact.firstName }} {{ ::contact.lastName }}</h2>が削除され、すべてが機能します。

関連する問題