angular+directive 명령 봉인

1639 단어 angular
1. 프로젝트 의존 (루트, 필터, 지령, 서비스 등)
var app = angular.module('qinYuan', ['ngRoute', 'qinyuanFilters', 'qinyuanDirective', 'QYtable']).config(function() {});  

2. 설정 문법
var directiveModule = angular.module('qinyuanDirective', []);
directiveModule.directive("citys", function($timeout) {
    return {
        restrict: 'AE',    
        // , 'AE'    :A( ),E( ),M( ),C( )
        templateUrl: "pages/common/city.html",   // :
       template:"
",// scope:{} // , , link: function(scope, elem, attrs) { } } })

3. directive와 컨트롤러의 상호작용
app.controller('ctrl',function($scope){     // 
    $scope.alert = function(a){
        alert(a);
    }
})

app.directive('check',function(){           // click
    return{
        restrict:'AE',
        link:function(scope,element,attr){
            element.bind('click',function(){
                 scope.alert(this.innerHTML);
            })
        }
    }
})

 
4. directive 간의 상호작용
.directive("b",function(){
   return {
    restrict:'AE',
    controller:function($scope,$element,$attrs,$transclude){
    $scope.name="alex",
    this.alert=function(a){
           alert(a)    
    }
  }
}
})


.directive("a",function(){
   return {
    restrict:'AE',
    require:"^b",  // 
    link:function(scope,element,attrs,bCtrl){
         bCtrl.alert(scope.name)
    } 
}
})

좋은 웹페이지 즐겨찾기