私のシナリオは一見単純ですが、私は成功せずに多くのアプローチを試みました。 私のコントローラーでフィルターを呼び出す必要があります。このフィルターはマスク用です。これを348.8456.979-90にしてください。 1:まあ、下の私のコードに従ってください私のモジュール:コントローラからカスタムフィルタのanglejsを呼び出してください
angular.module('webclientody', []);
angular.module('webclientody').filter('cpf', function() {
return function (input) {
var str = input + '';
if (str.length <= 11) {
str = str.replace(/\D/g, '');
str = str.replace(/(\d{3})(\d)/, "$1.$2");
str = str.replace(/(\d{3})(\d)/, "$1.$2");
str = str.replace(/(\d{3})(\d{1,2})$/, "$1-$2");
}
return str;
};
});
私のコントローラ:私はこのコードをカットし、小さな独立したプロジェクトでそれをテストする場合
angular.module('webclientody').controller('LoginCtrl', function ($scope,
$http, $location, $cookies, $rootScope, apiUrl, $filter) {
$scope.init = function() {
var cpf = "348845697990";
cpf = $filter("cpf")(cpf);
};
$scope.init();
});
を、それが動作します。しかし、私のプロジェクトでは、エラーが発生します:
> Error: [$injector:unpr] http://errors.angularjs.org/1.5.5/$injector/unpr?p0=cpfFilterProvider%20%3C-%20cpfFilter
at angular.js:38
at angular.js:4458
at Object.d [as get] (angular.js:4611)
at angular.js:4463
at Object.d [as get] (angular.js:4611)
at angular.js:19531
at b.$scope.init (LoginCtrl.js:6)
at new <anonymous> (LoginCtrl.js:10)
at Object.invoke (angular.js:4665)
at R.instance (angular.js:10115)
私はいくつかのアプローチを試みましたが、常にこのエラーを返します。誰でも何か提案がありますか?
Tksたくさん!
TKSを、残念ながらそれは動作していません。 –
コンソールに何のエラーがありますか? –
バディー、エラーは発生しません。フィルタを適用しないだけです。フィルタを使わずに解決しました。答えをありがとう! –