Directives
Directives are a unique and powerful feature available in AngularJS. Directives let you invent new HTML syntax, specific to your application.
Reusable Components
We use directives to create reusable components. A component allows you to hide complex DOM structure, CSS, and behavior. This lets you focus either on what the application does or how the application looks separately.
Localization
An important part of serious apps is localization. AngularJS's locale aware filters and stemming directives give you building blocks to make your application available in all locales.
[index.html]
- <!doctype html>
- <html ng-app=
"app"
> - <head>
- <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular.min.js"></script>
- <script src="components.js"></script>
- <script src="app.js"></script>
- </head>
- <body>
- <
tabs
> - <
pane
title
="Localization
"> - <span>Date: {{ '2012-04-01' | date:'fullDate' }}</span><br>
- <span>Currency: {{ 123456 | currency }}</span><br>
- <span>Number: {{ 98765.4321 | number }}</span><br>
- </pane>
- <pane title="
Pluralization
"> - <div ng-controller="
BeerCounter
"> - <div ng-repeat="beerCount in beers">
- <
ng-pluralize
count
="beerCount"when
="beerForms"></ng-pluralize> - </div>
- </div>
- </pane>
- </tabs>
- </body>
- </html>
[components.js]
- angular.module('components', [])
- .
directive
('tabs
', function() { - return {
-
restrict
: 'E', -
transclude
: true, -
scope
: {}, -
controller
: function($scope
,$element
) { - var panes = $scope.panes = [];
- $scope.
select
= function(pane) { - angular.forEach(panes, function(pane) {
- pane.selected = false;
- });
- pane.selected = true;
- }
- this.
addPane
= function(pane) { - if (panes.length == 0) $scope.select(pane);
- panes.push(pane);
- }
- },
-
template
: - '<div class="tabbable">' +
- '<ul class="nav nav-tabs">' +
- '<li ng-repeat="pane in panes" ng-class="{
active
:pane.selected}">'+ - '<a href=""
ng-click
="select(pane)">{{pane.title}}</a>' + - '</li>' +
- '</ul>' +
- '<div class="tab-content"
ng-transclude
></div>' + - '</div>',
-
replace
: true - };
- })
- .directive('pane', function() {
- return {
-
require
: '^tabs', - restrict: 'E',
- transclude: true,
- scope: { title: '@' },
- link: function(scope, element, attrs,
tabsController
) { - tabsController.addPane(scope);
- },
- template:
- '<div class="tab-pane" ng-class="{active: selected}" ng-transclude>' +
- '</div>',
- replace: true
- };
- })
[app.js]
- angular.module('app', ['
components
']) - .controller('BeerCounter', function($scope,
$locale
) { - $scope.
beers
= [0, 1, 2, 3, 4, 5, 6]; - if ($locale.
id
== 'en-us') { - $scope.
beerForms
= { - 0: 'no beers',
- one: '{} beer',
- other: '{} beers'
- };
- } else {
- $scope.beerForms = {
- 0: 'žiadne pivo',
- one: '{} pivo',
- few: '{} pivá',
- other: '{} pív'
- };
- }
- });
출처 - angularjs.com
인프런 인강 55%할인 쿠폰 - 커피한잔으로 Vue.js 핵심 강의!
인프런 인터넷 강의 55% 할인 쿠폰 - 커피한잔(5000원)으로 배우는 Vue.js 핵심 강의! 모바일 환경에서도 강의를 수강할 수 있도록 강의가 많이 개선되었습니다. 인프런 인터넷 강의 선착순 100명 55% �
plogger.tistory.com
[Vue.js 입문] 초보 실전 웹앱 개발 - 1부 : vue 개념 ~ 핵심 문법 - 인프런
이 강의를 수강하시면 Vue.js 와 관련된 기본적인 개념부터 Real 웹앱 개발을 해 볼 수 있습니다. 이 강의는 1부 기본기 이며, 2부와 3부를 통해서 실제 Real 웹앱을 구현해 보도록 하겠습니다. 초급 ��
www.inflearn.com
반응형
'Frontend > angularjs' 카테고리의 다른 글
[Hoon] AngularJS Seed - the seed for AngularJS apps (0) | 2019.01.04 |
---|---|
[Hoon] AngularJS - Angularjs Tutorial (0) | 2019.01.04 |
[Hoon] AngularJS - PhoneCat Tutorial App (0) | 2019.01.03 |
[Hoon] AngularJS - Create Components (0) | 2018.12.31 |
[Hoon] AngularJS - The AngularJS (0) | 2018.12.31 |
댓글