4
votes

I have my controller as "chatnow" and replacing the $scope.iid for title using $stateParams. But the chat messages are updated in a separate variable. I can update the messages at the interface using the following code but title not printed. When i remove the controller name title gets printed and not the messages. Help me out where i am going wrong.?

App.js :

.state('chatnow', {
  url: '/chatnow/:jid',
  templateUrl: 'templates/chatnow.html',
  controller: 'ChatNow'
});

Controller.js

.controller('ChatUserClick', function($rootScope, $scope, $stateParams, $ionicPopup, $state, SendMessage, SharedProperties, ChatMessageService, Profile)   {
  $scope.iid = $stateParams.jid;
  $scope.userJid = $stateParams.jid;
  var sharedData = SharedProperties.sharedObject;
  var MC = this;
  MC.list = ChatMessageService.getList($scope.curchatjid);
})

Chat.html

<ion-view title="{{MC.iid}}" ng-controller="ChatNow as MC">
  <ion-content class="chat">
    <ion-list>
      <li class="item chat-msg-wrap" ng-class="{'msg-send': todo.dt == 'send'}" ng-repeat="todo in MC.list track by $index">
        <div class="chat-msg">{{todo.msg}}</div>
      </li>
    </ion-list>
  </ion-content>
</ion-view>
1

1 Answers

3
votes

It is because you are using ng-controller with route/ state configuration. Remove the ng-controller from your view. When you use the ng-view directive, don't use the ng-controller along with it. The controller will be specified from the state configuration, in your case:

.state('chatnow', {
  url: '/chatnow/:jid',
  templateUrl: 'templates/chatnow.html',
  controller: 'ChatNow as MC'
});

The answer to this has been mentioned in this: https://stackoverflow.com/a/36881457/3878940