<Html> <Head> <Script src = "angular. min. js"> </script> <Script type = "text/javascript"> Function windowScopedFilter (input ){ Var output = []; Angular. forEach (input, function (v, k ){ If (v. phone. contains ("555 ")){ Output. push (v ); } }); Return output; } Var myapp = angular. module ('myfilterapp', []); Myapp. filter ('myfilter', function (){ Return function (input, param1 ){ Console. log ("--------------------------------------------------- begin dump of custom parameters "); Console. log ("input =", input ); Console. log ("param1 (string) =", param1 ); Var args = Array. prototype. slice. call (arguments ); Console. log ("arguments =", args. length ); If (3 <= args. length ){ Console. log ("param2 (string) =", args [2]); } If (4 <= args. length ){ Console. log ("param3 (bool) =", args [3]); } Console. log ("--------------------------------------------------- end dump of custom parameters "); // Filter If (5 <= args. length ){ Return window [args [4] (input ); } Return input; }; }); Myapp. controller ('myfiltercontroller', ['$ scope', function ($ scope ){ $ Scope. friends = [{name: 'john', phone: '2017-555 '}, {Name: 'Annie ', phone: '2017-BIG-MARY '}, {Name: 'Mike ', phone: '2017-555 '}, {Name: 'Adam ', phone: '2017-555 '}, {Name: 'David', phone: '2017-555 '}, {Name: 'mikay ', phone: '2017-555'}]; }]); </Script> </Head> <Body ng-app = "MyFilterApp"> <Div ng-controller = "MyFilterController"> <Table id = "searchTextResults"> <Tr> <th> Name </th> <th> Phone </th> </tr> <Tr ng-repeat = "friend in friends | myfilter: 'param1': 'param2': true: 'windowscopedfilter'"> <Td >{{ friend. name }}</td> <Td >{{ friend. phone }}</td> </Tr> </Table> </Div> <Hr> </Body> </Html> |