Thursday, October 16, 2014

maintaining position in list when history back

Recently I was ordered that I have to change paging list way to infinite list, that mean I have to query with special key, not page number.

I have to think seriously, can I do this???

I searched other homepages if there are hompages that use this pattern.
Best homepage was Facebook to benchmark

Facebook show us topic in timeline and if scroll to bottom , ajax will get more data from the server.

but there are something that i should consider carefully. 
what is that???

for example, i choose one topic and go backpage, list page will refresh and position I last saw will be lost.
In other word, ajax loading data dosen't save homepage last state.

To solve this problem.
I Think step.

1. in my list page, call list data from the server using ajax.
2. I scroll some position.
3. I click some data.
  - I have to check scroll.x scroll.y and save in history.
4. detail page show
5. go back to list page
6. get the last scrollx, scroll.y from saved data 
   - ajax call againg
7. and scroll to last position.

this is what I think
I might be good to change what I'm now working on.

Test Script
1. History.js
2. Iscroll4 

Monday, October 13, 2014

Element ready after appending data.

In jquery, there I can catch callback when data is fully loaded .

I wanted to knwo maybe in angularjs has too.
I searched much time and find out how to use
below is just example.


angular.element(document.querySelector('#contentBox')).append(data).ready(function(){
//                alert('ready complete');
         $scope.loaded();

});


and 

angular.element i can use jquery lite 
reference by 

Sunday, October 5, 2014

angular ng-if

how can I check if data is over number or like when in jstl
there i can use ng-if

for example .


referenced by https://code.angularjs.org/1.1.5/docs/api/ng.directive:ngIf

  1. <span ng-if="checked" ng-animate="'example'">
  2. I'm removed when the checkbox is unchecked.
  3. </span>

Thursday, September 18, 2014

if you are in trouble

take step back and think carefully.

My Thought about AngularJs

I used it for a half year.

First time I started it~ It was amazing because each input or text automatically know data is changed.

and I wanted know more and more ~

I will write what is very difficult to be skillful

Difficult Thing
  - understanding directive.
  - directives are very difficult to study
    scope, link, compile, restrict, transclude and so on...
  - communication controllers, controllers inherit
  - services

if I'm familiar with angularjs

Usefull Thing
  - project speed is upup ~
  - easy ajax network and databinding
  - custom common directives and i can use it
  - one page app
  - MVC structure

Wednesday, September 17, 2014

Directive example

directive

1. restrict

A 엘리먼트
E 속성
C 클래스


2. template or templateUrl

실제로 들어가게 되는 div

3. 특징
- directive는 새로운 scope를 생성할 수 없다
- scope를 부모로 부터 상속을 받는다
-

app.directive('helloWorld', function() {
  return {
    restrict: 'AE',
    replace: true,
    template: '<p style="background-color:{{color}}">Hello World',
    link: function(scope, elem, attrs) {
      elem.bind('click', function() {
        elem.css('background-color', 'white');
        scope.$apply(function() {
          scope.color = "white";
        });
      });
      elem.bind('mouseover', function() {
        elem.css('cursor', 'pointer');
      });
    }
  };
});

4. link fuction
- link에는 3개의 변수가 들어간다
- scope는 parent 스코프

5. scope의 종류는 두가지가 있다
- A child scope     -> scope:true
- An isolated scope -> scope:{}

childe scope 는 부모로부터 scope를 상속받는다
isolated scope 는 개별적으로 하나를 생성한다.

isolated scope는 부모의 scope를 사용할 수 없는것이 아니다.

6. @ 사용하기 (데이터 바인딩용)
- @ for One Way Text Binding
- 상위 컨트롤러의 color가 바뀌면 하위의 내용도 따로 바뀐다.

app.directive('helloWorld', function() {
  return {
    scope: {
      color: '@colorAttr'
    },
    ....
    // the rest of the configurations
  };
});


<body ng-controller="MainCtrl">
  <input type="text" ng-model="color" placeholder="Enter a color"/>
  <hello-world color-attr="{{color}}"/>
</body>


7. = 사용하기 (데이터 바인딩용)
= for Two Way Binding

app.directive('helloWorld', function() {
  return {
    scope: {
      color: '='
    },
    ....
    // the rest of the configurations
  };
});


8. & to Execute Functions in the Parent Scope

app.directive('sayHello', function() {
  return {
    scope: {
      sayHelloIsolated: '&amp;'
    },
    ....
    // the rest of the configurations
  };
});

<body ng-controller="MainCtrl">
  <input type="text" ng-model="color" placeholder="Enter a color"/>
  <say-hello sayHelloIsolated="sayHello()"/>
</body>



9. Parent Scope vs. Child Scope vs. Isolated Scope

Parent Scope : scope:fasle default
childe scope : scope:true   inherit parent scope
isolated scope :


10. The controller Function and require
app.directive('outerDirective', function() {
  return {
    scope: {},
    restrict: 'AE',
    controller: function($scope, $compile, $http) {
      // $scope is the appropriate scope for the directive
      this.addChild = function(nestedDirective) { // this refers to the controller
        console.log('Got the message from nested directive:' + nestedDirective.message);
      };
    }
  };
});

4번째 변수는 require 한 컨트롤러가 삽입된다.

app.directive('innerDirective', function() {
  return {
    scope: {},
    restrict: 'AE',
    require: '^outerDirective',
    link: function(scope, elem, attrs, controllerInstance) {
      //the fourth argument is the controller instance you require
      scope.message = "Hi, Parent directive";
      controllerInstance.addChild(scope);
    }
  };
});



reference site : http://www.sitepoint.com/practical-guide-angularjs-directives-part-two/

Tuesday, September 16, 2014

call Angularjs Scope from javascript fn

I found out that how I call angularjs scope's function from javascript

example is blow

angular.element(document.getElementById('yourControllerElementID')).scope().get();