목록javascript (23)
내맘대로 살기🎉
필터는 배열의 데이터와 함께 사용한다. 또한, 루프 밖에서 사용이 가능하다. 특정 조건에 만족하는 데이터만 구하고 싶을 때 사용. (예를 들어 에 입력된 값으로만 사용자를 구하고 싶을 때) 전역으로 선언 myApp.filter('reverse', function () { return function (input, uppercase) { var out = ''; for (var i = 0; i < input.length; i++) { out = input.charAt(i) + out; } if (uppercase) { out = out.toUpperCase(); } return out; } }); // 데이터를 제공하는 컨트롤러 myApp.controller('MainCtrl', ['$scope', fun..
서비스 myApp.service('Math', function () { this.multiply = function (x, y) { return x * y; }; }); - Math 콘텍스트(콘텍스트라는 명칭이 맞는지 의심됨.)에 multiply라는 메소드를 추가한다. myApp.controller('MainCtrl', ['$scope', function ($scope) { var a = 12; var b = 24; // 결과는 288 var result = Math.multiply(a, b); }]); - controller안에 서비스를 위와 같이 사용할 수 있다. // Math를 주입한다 myApp.controller('MainCtrl', ['$scope', 'Math', function ($scop..
Click me 위의 것을 jsfiddle.net - html에 작성하고. var myApp = angular.module('myApp', []); myApp.directive('customButton', function () { return { restrict: 'AC', replace: true, transclude: true, template: '' + '' + '', link: function (scope, element, attrs) { // DOM manipulation/events here! } }; }); 위의 것을 jsfiddle.net - javascript에 작성한다. 디렉티브는 여러개의 속성을 가지는 객체를 반환하는데, restrict, replace, transclude, temp..