app.directive("name", function () {
controller : function () {
},
link:function(scope,elem,attr,contr){
// от сюда
// взять this котроллера . например selfContr
selfContr.method = fucntion () {
return elem
}
}
}
app.directive("name2", function () {
require : "name",
controller : function () {
//this
},
link:function(scope,elem,attr,contr){
contr.method();
}
}
// Code goes here
angular.module('app', [])
.controller('FooCtrl', FooController)
.controller('BarCtrl', BarController)
.directive('foo', fooDirective)
.directive('bar', barDirective);
FooController.$inject = ['$window'];
function FooController($window) {
this.notify = function() {
$window.alert('foo ctrl');
};
}
FooController.$inject = ['$window'];
function BarController($window) {
this.notify = function() {
$window.alert('bar ctrl');
};
}
function fooDirective() {
return {
controller: 'FooCtrl'
};
}
function barDirective() {
return {
controller: 'BarCtrl',
controllerAs: 'ctrl',
require: 'foo',
link: function(scope, elem, attrs, ctrl) {
if (elem[0].tagName === 'A') {
elem.on('click', function() {
ctrl.notify();
});
} else {
elem.on('click', function() {
scope.ctrl.notify();
});
}
}
};
}
app.directive("name", function () {
controller : function ($scope) {
var self = this;
$scope.toThis = function (name , data ) {
self[name] = data
}
},
link:function(scope,elem,attr,contr){
scope.toThis("slide", elem)
}
}
app.directive("name2", function () {
require : "name",
controller : function () {
//this
},
link:function(scope,elem,attr,contr){
contr.slide
}
}