I did a lot of workaround, searched and researched, but I can't figure how to achieve my goal.
- The problem:
-Where I get confused:
-How I hope solve it:
<input type="text" name="newComission_dateFrom" ng-model="newCommission.from" notincluded=myFunction({{$index}})/>
and the function myFunction, will iterate over a list that contains all the addedCommissionsDates and will compare it with all the ranges of dates, except with the range contained in addedCommisionsDates[index].
The objective is can evaluate an expression in an attribute without use an isolated scope.
I had a lot of problems with isolated scopes, and I finished agreeing with this post:
When writing a directive, how do I decide if a need no new scope, a new child scope, or a new isolate scope?.
EDIT I was looking how was implemented ngRequire, because ngRequire can accept ng-require="aFunction()", I reached this goal in my directive, using $parsers. So, I can execute a function now! I did some progress using this, but I want to have the result of execute the function in my directive, I want to reach something like this
rangesToEval = //the result of my function or expression.
Looking the things that have ngRepeat, I can't figure in what scope is the value that return this function
if(attrs.notincluded) {
var notIncludedValidator = function(value) {
ngModelCtrl.$setValidity('notincluded', !attrs.notincluded);
return value;
};
}
all works good because I'm using a boolean, but, I want to use a list that is the result of execute the expresion in the attribute notincluded
//This input is part of a ng-repeat
<input type="text" ng-model="commission.date" ng-required="true" notincluded="filterDatesFn({{$index}})" />
I have the function in my controller:
$scope.filterDatesFn = function(index) {
// in this list, we will add the dates of the defined commissions
if($scope.addedCommisionsDate) {
var listToEvalue= [];
for ( var i = 0; i < $scope.addedCommisionsDate.length; i++) {
if(i != index) {
listToEvalue.push($scope.addedCommisionsDate[i]);
}
}
return listToEvalue;
}
};
So my next objective is can change to:
if(attrs.notincluded) {
var notIncludedValidator = function(value) {
--put the listToEvalue here and do my comparations and validate or invalidate the form in base of the comparation That I do here.
return value;
};
}
I will be posting the progress of this research.
I will be grateful is somebody can help or share any idea
See you later!
AngularJS DirectivesThe ng-app directive initializes an AngularJS application. The ng-init directive initializes application data. The ng-model directive binds the value of HTML controls (input, select, textarea) to application data. Read about all AngularJS directives in our AngularJS directive reference.
The ng-app directive is used to initialize the AngularJS application.
AngularJS expressions can be written inside double braces: {{ expression }} . AngularJS expressions can also be written inside a directive: ng-bind="expression" . AngularJS will resolve the expression, and return the result exactly where the expression is written.
The above output will be produced when we add $$, since, it acts as private object. So, to prevent accidental name collisions while writing your code angular prefixes public objects with $ and private objects with $$. Like 1.
have you tried pass this function like '&' parameter in your directive?
like that:
App.directive('myDirective', function(){
return {
scope: {
myFc: '&'//if the name of parameter is the same in html if not use '&nameOfParameter'
},
link: function($scope, $el, $attr){
$el.bind('click', function(value){
$scope.myFc(value)
})
}
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With