valor obtener con angularjs angularjs-scope angular-filters

obtener - ng-value angularjs



AngularJS-Access $ scope desde el controlador en filtro personalizado (3)

Debe proporcionar el atributo de ámbito deseado al filtro.

Puedes hacerlo así:

Filtrar:

app.filter(''myCustomFilter'', function ($filter) { return function (date,myVar1) { /* Do some stuff with myVar1 */ }; });

HTML:

<tr ng-repeat="data in MyData" ng-class="{true: ''green'', false:''red''}[data.Date | myCustomFilter:var1]"> </tr>

Tengo un controller con varios $scopes . Necesito acceder a uno de estos $ scopes en un filtro personalizado:

app.controller(''AppController'', function($scope) { $scope.var1 = ''Some data1''; $scope.var2 = ''Some data2''; } ); app.filter(''myCustomFilter'', function ($filter) { return function (date) { var date = date; }; }); <tr ng-repeat="data in MyData" ng-class="{true: ''green'', false:''red''}[data.Date | myCustomFilter]"> </tr>

¿Cómo puedo pasar $ scope.var1 en mi myCustomFilter ?


var app = angular.module(''app'', []); app.controller(''AppController'', function($scope) { $scope.var1 = 2; $scope.var2 = 3; $scope.MyData = [{ Date: 1 }, { Date: 2 }, { Date: 3 }] } ); app.filter(''myCustomFilter'', function($filter) { return function(date, scopeValue) { var date = date; return date * scopeValue }; });

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <body> <div ng-app="app"> <div ng-controller="AppController"> <li ng-repeat="data in MyData"> Date: {{data.Date}} | Date after myCustomFilter: {{data.Date | myCustomFilter : var1}} </li> </div> </div> </body>


app.filter(''myCustomFilter'', function ($filter) { return function (date, scope) { // add scope here var date = date; }; }); ng-class="{true: ''green'', false:''red''}[data.Date | myCustomFilter:this]">