我的控制器是"聊天"并使用$ 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>
答案 0 :(得分:3)
这是因为您正在使用ng-controller
进行路由/状态配置。从视图中删除ng-controller
。当您使用ng-view
指令时,请不要同时使用ng-controller。在您的情况下,将根据状态配置指定控制器:
.state('chatnow', {
url: '/chatnow/:jid',
templateUrl: 'templates/chatnow.html',
controller: 'ChatNow as MC'
});