Ниже приведены две директивы. Моя проблема в том, что функция addSectorAttributes в моей второй директиве дважды запускалась по ng-click из project_subtypes.html.Угловая функция вызова функции вызова дважды
.directive('projectFilter', function($compile, $timeout){
return {
restrict: 'E',
templateUrl: 'project_filter.html',
link : function(scope,element, attr){
//getting data and fill the html from a service
},
controller: function ($scope) {
$scope.addSubTypes = function (event,id) {
var ex = $(event.currentTarget);
var el = $compile("<project-subtypes typeid="+id+" class='slide-content'></project-subtypes>")($scope);
ex.parent().append(el);
};
}
}
})
.directive('projectSubtypes', function($compile){
return {
restrict: 'E',
scope: true,
templateUrl: 'project_subtypes.html',
link : function(scope,element,attr){
//getting data and fill the html from a service
var id = attr.typeid;
sectorFiltering.getSectorSubTypes(id).success(function(data) {
scope.sector_subtypes = data.sector_subtypes;
});
});
},
controller: function ($scope) {
$scope.addSectorAttributes = function (event,id) {
console.log("teeest"); // called twice.....
};
}
}
})
project_subtypes.html
<li ng-repeat="subtype in substype.subtypes">
<div layout='row' class='load-attributes' ng-click=" addSectorAttributes($event, subtype.id)"></div>
</li>
Любая помощь, пожалуйста ....
Вы намерены повторить на литий или DIV? – Robert
@Robert повторить на литий –
Вы можете добавить образец кода, который показывает проблему? –