Heim > Fragen und Antworten > Hauptteil
首先定义一个directive:
app.directive('conversation', [function() {
return {
restrict: 'E',
templateUrl: 'conversation.html?date' + new Date().getTime(),
replace: true,
scope:{
conversations:"=",
changeConversation: "&"
},
link:function(scope, element, attributes){
}
};
}]);
调用
<conversation conversations="conversations" change-conversation="changeConversation(conversation)"></conversation>
<ul class="mdui-list">
<li class="mdui-list-item mdui-ripple" ng-repeat="conversation in conversations" ng-click="changeConversation(conversation)">
<p class="mdui-list-item-avatar">
<img ng-src="{{conversation.chatThumbLogo}}"/>
</p>
<p class="mdui-list-item-content">
<p class="mdui-list-item-title">{{conversation.chatName}}</p>
<!--<p class="mdui-list-item-text mdui-list-item-one-line">hello world</p>-->
<span class="im_badge" ng-bind="conversation.unreadCount" ng-if="conversation.unreadCount > 0"></span>
</p>
</li>
<li class="mdui-pider-inset mdui-m-y-0"></li>
</ul>
ng-click触发函数后不能打印conversation,undefined。
$scope.changeConversation = function (conversation) {
console.log(conversation);
}
世界只因有你2017-05-15 17:13:35
$scope.changeConversation = function (conversation);
这里是parent的scope,你parent的scope里并没有conversation这个变量。