사용자 지정 필터를 구현하려고합니다. angularjs에서 종속성 오류가 발생합니다.
아래는 내 코드입니다.
angular.module('Test', [])
.controller('TestController', ['$scope', function ($scope) {
$scope.myDate = 1456106575956;
}])
.filter('utcToDate', function(pUTCString) {
return function(pUTCString) {
return new Date(pUTCString);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="Test" ng-controller="TestController">
{{myDate | utcToDate:myDate }}
</body>
당신의 JS는
angular.module('Test', [])
.controller('TestController', ['$scope', function ($scope) {
$scope.myDate = 1456106575956;
}])
.filter('utcToDate', function() {
return function(pUTCString) {
return new Date(pUTCString);
}
});
HTML은 괜찮지 만 다음과 같이 작성할 수도 있습니다.
<body ng-app="Test" ng-controller="TestController">
{{myDate | utcToDate }}
</body>
무엇이 잘못 되었나요?
여기서 수행 한 것처럼 사용자 지정 필터에 대한 함수를 정의하는 동안 매개 변수를 지정할 필요가 없습니다.
.filter('utcToDate', function(pUTCString) {
공식 문서 에서 필터 에 대해 자세히 알아 보세요.
다음은 작동 데모입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다