angular.js - Why can't ng-click of directive in angularjs pass parameters?
滿天的星座
滿天的星座 2017-05-15 17:11:35
0
3
612

First define a 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){

        }
    };
}]);

Call

<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>

conversation, undefined cannot be printed after ng-click triggers the function.

 $scope.changeConversation = function (conversation) {
        console.log(conversation);
    }
滿天的星座
滿天的星座

reply all(3)
世界只因有你
$scope.changeConversation = function (conversation);

This is the parent’s scope. There is no conversation variable in your parent’s scope.

给我你的怀抱

I also think it’s @熊丸子说的那样,conversationThis variable is not the parent’s

我想大声告诉你

conversation This directive restrict: 'E', is an element and you did not reference it in the template

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template