user3818229 user3818229 - 1 year ago 118
AngularJS Question

List view not updating after changes from another controller in AngularJS

I don't know why, but my index.html doesn't want to be updated.
I will try to show my problem with code:

// Index.html part:

<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: track by"
ui-sref="{ id: })">
<img ng-src="./img/{{::contact.pic}}">
<h2>{{::contact.firstName }} {{ ::contact.lastName }}</h2>
<p ng-bind-html="::contact.department"></p>
<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>

As you can see there are two buttons which can make changes with my array. For deleting I'm using the same controller with displaying my items. Here everything is fine and the list of index view updating after button pressed.

The problem is in editing my items:

// IndexController part:

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

constructor($scope, $state, $q, $log, $ionicModal, $ionicListDelegate, contactsService) {
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;

function remove(event, item) {


<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-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 class="item item-input">
<span class="input-label">Last Name</span>
<input ng-model="editingItem.lastName" type="text">
<label class="item item-input">
<span class="input-label">Email</span>
<input ng-model="" type="text">
<div class="list">
<label class="item item-input item-select">
<div class="input-label">
Select Manager
<select name="managerSelection" ng-model="editingItem.managerId">
<option ng-repeat="manager in contactEditCtrl.contacts" value="{{}}">{{manager.firstName + " " + manager.lastName}}</option>
<button class="button button-full button-positive" ng-click="save(editingItem)">Save Edits</button>

of contacts in the

// Update method from service

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

// And functions from EditCtrl:

$ = function (item) {
contactsService.update($scope.editingItem).then((contacts) => {
vm.contacts = contacts;

I do the same things but the main view with all contacts updating only after page refresh. Also if I open my model window after editing the contact has updated values. Whats the problem with my code?
Thanks in advance!

Answer Source

The problem is in "One-time binding" I just deleted :: before <h2>{{::contact.firstName }} {{ ::contact.lastName }}</h2> and everything get worked!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download