Сообщение от Shitbox2
|
Есть два варианта, как это сделать
|
3. коллбэк в
модель контроллер
Сообщение от Shitbox2
|
Какие есть мысли по этому поводу?
|
без тестового кода мыслей нет
<!DOCTYPE html>
<html id="ng-app" ng-app="app"> <!-- id="ng-app" IE<8 -->
<head>
<title>sandbox</title>
<script src="http://code.angularjs.org/1.1.5/angular.min.js"></script>
<script>
angular
.module( 'directives', [])
.directive( 'ngMy', function() {
return {
scope: {
callback: '&'
},
link: function( $scope, $element ) {
$element.bind( 'click', function() {
console.log( 1 );
$scope.callback();
});
}
};
});
var app = angular.module( 'app', [ 'directives' ]);
app.controller( 'MainController', function( $scope, $http ) {
$scope.fn = function() {
console.log( 2 );
};
});
</script>
</head>
<body ng-controller="MainController">
<div ng-my callback="fn()" style="background-color: lavender; height: 100px;">
click on this element and see in console
</div>
</body>
</html>