내맘대로 살기🎉
실제 서버의 XHR 호출을 한다. $http 메소드는 Angular가 서버 데이터에 접근하는 기능을 래핑한 메소드이다. myApp.controller('MainCtrl', '$http' ['$scope', function ($scope, $http) { $http({ method: 'GET', url: '//localhost:9000/someUrl' }) .success(function (data, status, headers, config) { // 성공! 데이터를 가져왔어 }) .error(function (data, status, headers, config) { // 이런. 뭔가 잘못되었음! :( }); }]); -- GET요청을 보내고 성공인지 실패인지 확인한다. { "user": { "name..
textarea의 스크롤이 있는지 없는지 확인하는 것이 필요했다. (function($) { $.fn.hasScrollBar = function() { return this.get(0).scrollHeight > this.innerHeight(); } })($); - 스크롤의 유무를 확인하는 function을 직접 만들어줘서 사용하면 된다. fn에 대해 찾아봤는데, fn 속성은 prototype 속성의 가명이라고 한다.또한, prototype과 fn은 완전히 같은 것이라고 한다.
양방향 데이터 바인딩이란, 완전히 동기화된 데이터라고 생각하면 좋다. 모델을 갱신하면 뷰에 반영되고, 뷰를 갱신하면 모델에 반영되는 형태이다. * 동기화를 위한 다른 작업을 하지 않아도 자동으로 동기화. My model data: {{ myModel }} - view단의 에서 myModel이라는 모델을 연결. var myApp = angular.module('myApp', []); myApp.controller('MainCtrl', ['$scope', function ($scope) { $scope.myModel = ''; }]); 실제 출력 화면의 textbox에 입력해보면 My model data에 값이 바로바로 동기화되는 것을 확인할 수 있다. * 출처 : http://soomong.net/blog..
필터는 배열의 데이터와 함께 사용한다. 또한, 루프 밖에서 사용이 가능하다. 특정 조건에 만족하는 데이터만 구하고 싶을 때 사용. (예를 들어 에 입력된 값으로만 사용자를 구하고 싶을 때) 전역으로 선언 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..
ex ) localhost/router?id=1 localhost/router?id=2 localhost/router?id=3 ? 뒤에 나타는 것{id=(1~3)}을 query string이라고 한다. 응답, 요청 (req), (res) res.send(req.query.id); 이렇게 하고 router?id=1이라고 url을 작성하면 html에 1이 출력. * expressjs.com에 접속하여 API reference를 보는 것도 좋다. localhost/topic?id=1&name=harris id와 name 둘 다 가져온다. 중간에 연결자는 &이다. app.get('/topic/:id',function(req, res){ var topics = [ 'Javascript is...', 'Nodejs..