154
rated 0 times
[
157]
[
3]
/ answers: 1 / hits: 15507
/ 11 Years ago, sat, november 2, 2013, 12:00:00
I created a directive in angular where its scope is not isolated
<div ng-controller=myController>
<ul>
<li myDirective=model[1].list >a lot more things will happen inside here</li>
</ul>
</div>
CONTROLLER:
app.controller(myController,[$scope,function($scope){
$scope.model = [
{
list:[ object1,object2,object3 ]
},
{
list:[ object4,object5,object6 ]
},
{
list:[ object7,object8,object9 ]
}
]
}]);
Directive:
app.directive(myDirective,[function(){
return {
scope:true,
controller:function($scope,$element,$attrs){
/*
How do I directly be able to manipulate from inside here what is assigned
on the $attrs.myDirective
without ISOLATING the scope of the directive
*/
}
}
}]);
one of the solution i used was this function i put this inside the directive and process the string assigned to the $attrs.myDirective it works well with model.list
but with model[2].list it doesnt because its not built for it. How do I modify this function or are there better solutions for this problem...
$scope.rediks = function(string)
{
var scope = $scope;
var scopeSplit = string.split('.');
for (i = 0; i < scopeSplit.length - 1; i++)
{
scope = scope[scopeSplit[i]];
if (scope == undefined) return;
}
return scope[scopeSplit[scopeSplit.length - 1]];
}
Thank you very much,
More From » string