问题描述:

more angular confusion. namely, why cannot i bind a child element of a directive to a click event?

app.directive('expandingTile', [function() {

return {

restrict: 'A',

link: function(scope, elem, attrs) {

elem.bind('click', function() {

console.log('elem hit!');

});

elem.find('div#CloseBtn').bind('click', function() {

console.log('found child hit!')

});

}

}

}]);

网友答案:

Try using this

link: function (scope, element) {
    $timeout(function () {
        element.on('click', '#Id', function () {
            console.log('inside event handler of the first child)
        })
    })
}
相关阅读:
Top