关于离子视图的标题[ion-view]

时间:2016-04-28 06:36:28

标签: angularjs controller ionic-framework ionic-view

我的控制器是"聊天"并使用$ stateParams替换$ scope.iid作为标题。但聊天消息在单独的变量中更新。我可以使用以下代码更新界面上的消息,但不打印标题。当我删除控制器名称标题被打印而不是消息。帮助我摆脱错误的地方。?

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 个答案:

答案 0 :(得分:3)

这是因为您正在使用ng-controller进行路由/状态配置。从视图中删除ng-controller。当您使用ng-view指令时,请不要同时使用ng-controller。在您的情况下,将根据状态配置指定控制器:

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

这里提到了答案:https://stackoverflow.com/a/36881457/3878940