AngularJS Filters 맞춤 필터
AngularJS Filters 맞춤 필터
모듈에 새 필터 팩토리 함수를 등록하여 고유 한 필터를 만들 수 있습니다.
"myFormat"이라는 사용자 정의 필터를 만듭니다.
<ul ng-app="myApp" ng-controller="namesCtrl">
<li ng-repeat="x in names">
{{x | myFormat}}
</li>
</ul>
<script>
var app = angular.module('myApp', []);
app.filter('myFormat', function() {
return function(x) {
var i, c, txt = "";
for (i = 0; i < x.length; i++) {
c = x[i];
if (i % 2 == 0) {
c = c.toUpperCase();
}
txt += c;
}
return txt;
};
});
app.controller('namesCtrl', function($scope) {
$scope.names = ['Jani', 'Carl', 'Margareth', 'Hege', 'Joe', 'Gustav', 'Birgit', 'Mary', 'Kai'];
});
</script>
myFormat필터는 다른 모든 문자를 대문자로 포맷합니다.
[전체소스]
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<ul ng-app="myApp" ng-controller="namesCtrl">
<li ng-repeat="x in names">
{{x | myFormat}}
</li>
</ul>
<script>
var app = angular.module('myApp', []);
app.filter('myFormat', function() {
return function(x) {
var i, c, txt = "";
for (i = 0; i < x.length; i++) {
c = x[i];
if (i % 2 == 0) {
c = c.toUpperCase();
}
txt += c;
}
return txt;
};
});
app.controller('namesCtrl', function($scope) {
$scope.names = [
'Jani',
'Carl',
'Margareth',
'Hege',
'Joe',
'Gustav',
'Birgit',
'Mary',
'Kai'
];
});
</script>
<p>Make your own filters.</p>
<p>This filter, called "myFormat", will uppercase every other character.</p>
</body>
</html>
모듈에 새 필터 팩토리 함수를 등록하여 고유 한 필터를 만들 수 있습니다.
"myFormat"이라는 사용자 정의 필터를 만듭니다.
<ul ng-app="myApp" ng-controller="namesCtrl">
<li ng-repeat="x in names">
{{x | myFormat}}
</li>
</ul>
<script>
var app = angular.module('myApp', []);
app.filter('myFormat', function() {
return function(x) {
var i, c, txt = "";
for (i = 0; i < x.length; i++) {
c = x[i];
if (i % 2 == 0) {
c = c.toUpperCase();
}
txt += c;
}
return txt;
};
});
app.controller('namesCtrl', function($scope) {
$scope.names = ['Jani', 'Carl', 'Margareth', 'Hege', 'Joe', 'Gustav', 'Birgit', 'Mary', 'Kai'];
});
</script>
myFormat필터는 다른 모든 문자를 대문자로 포맷합니다.
[전체소스]
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<ul ng-app="myApp" ng-controller="namesCtrl">
<li ng-repeat="x in names">
{{x | myFormat}}
</li>
</ul>
<script>
var app = angular.module('myApp', []);
app.filter('myFormat', function() {
return function(x) {
var i, c, txt = "";
for (i = 0; i < x.length; i++) {
c = x[i];
if (i % 2 == 0) {
c = c.toUpperCase();
}
txt += c;
}
return txt;
};
});
app.controller('namesCtrl', function($scope) {
$scope.names = [
'Jani',
'Carl',
'Margareth',
'Hege',
'Joe',
'Gustav',
'Birgit',
'Mary',
'Kai'
];
});
</script>
<p>Make your own filters.</p>
<p>This filter, called "myFormat", will uppercase every other character.</p>
</body>
</html>
게시판 목록
퍼블리싱강좌
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 178 | AngularJS | 8년 전 | 1422 | ||
| 177 | AngularJS | 8년 전 | 1196 | ||
| 176 | AngularJS | 8년 전 | 1271 | ||
| 175 | AngularJS | 8년 전 | 1362 | ||
| 174 | AngularJS | 8년 전 | 1136 | ||
| 173 | AngularJS | 8년 전 | 1876 | ||
| 172 | AngularJS | 8년 전 | 1431 | ||
| 171 | AngularJS | 8년 전 | 1127 | ||
| 170 | AngularJS | 8년 전 | 1389 | ||
| 169 | AngularJS | 8년 전 | 1186 | ||
| 168 | AngularJS | 8년 전 | 999 | ||
| 167 | AngularJS | 8년 전 | 1961 | ||
| 166 | AngularJS | 8년 전 | 1034 | ||
| 165 | AngularJS | 8년 전 | 1098 | ||
| 164 | AngularJS | 8년 전 | 1303 | ||
| 163 | AngularJS | 8년 전 | 1146 | ||
| 162 | AngularJS | 8년 전 | 1361 | ||
| 161 | AngularJS | 8년 전 | 1367 | ||
| 160 | AngularJS | 8년 전 | 1120 | ||
| 159 | AngularJS | 8년 전 | 1088 | ||
| 158 | AngularJS | 8년 전 | 1498 | ||
| 157 | AngularJS | 8년 전 | 1469 | ||
| 156 | AngularJS | 8년 전 | 1319 | ||
| 155 | AngularJS | 8년 전 | 1208 | ||
| 154 | AngularJS | 8년 전 | 1607 | ||
| 153 | AngularJS | 8년 전 | 1072 | ||
| 152 | AngularJS | 8년 전 | 1478 | ||
| 151 | AngularJS | 8년 전 | 1410 | ||
| 150 | AngularJS | 8년 전 | 1106 | ||
| 149 | AngularJS | 8년 전 | 1637 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기