2016-07-17 5 views
0

사용자 지정 지시문을 작성했습니다.링크 함수가 호출되지 않습니다

내 문제는 html 템플릿이 렌더링되지 않는다는 것입니다.

디버깅 후 인스턴스 함수가 ​​호출되지 않기 때문에 링크 함수가 호출되지 않습니다.

"debugger;"를 추가했습니다.

"디버거;"// 첫 번째 발언과 함께 호출됩니다. 그래서 지시문 js 파일은 게으른 로딩과 함께로드 알아요. 나는 지시어 사용하는 경우

<form name="newEggTabForm" class="form-details"> 
<div block-ui="main"> 
    <div loading-indicator> 
     <section class="form-horizontal form-details-section"> 
      <header class="form-details-header"> 
       <h4 class="title-sm">newegg</h4> 
      </header> 
      <div class="form-details-body"> 

       <label class="spaced-right-inside-lg"> 
        Enable or disable the newegg functionality for this product: 
       </label> 
       <div class="btn-group" role="group" aria-label="..."> 
        <button type="button" class="btn btn-default">Disabled</button> 
        <button type="button" class="btn btn-primary active">Enabled</button> 
       </div> 

      </div> 
     </section> 
     <section class="form-horizontal form-details-section"> 
      <header class="form-details-header"> 
       <h4 class="title-sm">newegg Marketplace Options</h4> 
      </header> 
      <div class="form-details-body"> 
       <div class="row"> 
        <div class="col-md-6"> 
         <div class="form-group"> 
          <label class="col-sm-3 col-md-4 control-label">newegg account:</label> 
          <div class="col-sm-9 col-md-8"> 
           <div class="btn-group" dropdown> 
            <button type="button" class="btn btn-default dropdown-toggle" dropdown-toggle> 
             Choose <span class="caret"></span> 
            </button> 
            <ul class="dropdown-menu" role="menu"> 
             <li><a href="">NewEggTestSeller</a></li> 
             <li><a href="">NewEggTestSeller2</a></li> 
            </ul> 
           </div> 
          </div> 
         </div> 
        </div> 
       </div> 
       <div class="form-group"> 
        <label class="col-sm-3 col-md-2 control-label">Industry and subcategory:</label> 
        <div class="col-sm-9 col-md-10"> 
         <div class="btn-group" dropdown> 
          <button type="button" class="btn btn-default dropdown-toggle" dropdown-toggle> 
           Choose <span class="caret"></span> 
          </button> 
          <ul class="dropdown-menu" role="menu"> 
           <li><a href="">Accessories (1)</a></li> 
           <li><a href="">Apparel (62)</a></li> 
          </ul> 
         </div> 
         <div class="btn-group" dropdown> 
          <button type="button" class="btn btn-default dropdown-toggle" dropdown-toggle> 
           Choose <span class="caret"></span> 
          </button> 
          <ul class="dropdown-menu" role="menu"> 
           <li><a href="">Air Conditioners</a></li> 
           <li><a href="">Air purifier</a></li> 
          </ul> 
         </div> 
        </div> 
       </div> 
       <div class="row"> 
        <div class="col-md-6"> 
         <div class="form-group"> 
          <label for="inputListingPrice" class="col-sm-3 col-md-4 control-label">newegg listing price:</label> 
          <div class="col-sm-9 col-md-8"> 
           <input type="text" class="form-control input-number" id="inputListingPrice" name="inputListingPrice"> 
          </div> 
         </div> 
        </div> 
       </div> 
       <div class="row"> 
        <div class="col-md-6"> 
         <div class="form-group"> 
          <label for="inputSellerPart" class="col-sm-3 col-md-4 control-label">Seller part #:</label> 
          <div class="col-sm-9 col-md-8"> 
           <input type="text" class="form-control" id="inputSellerPart" name="inputSellerPart"> 
          </div> 
         </div> 
         <div class="form-group"> 
          <label for="inputRelatedSellerPart" class="col-sm-3 col-md-4 control-label">Related seller part #:</label> 
          <div class="col-sm-9 col-md-8"> 
           <input type="text" class="form-control" id="inputRelatedSellerPart" name="inputRelatedSellerPart"> 
          </div> 
         </div> 
        </div> 
        <div class="col-md-6"> 
         <div class="form-group"> 
          <label for="customInput" class="col-sm-3 col-md-4 control-label">Condition:</label> 
          <div class="col-sm-9 col-md-8"> 
           <label class="radio-inline"> 
            <input type="radio" name="conditionRadios" checked=""> New 
           </label> 
           <label class="radio-inline"> 
            <input type="radio" name="conditionRadios"> Refurbished 
           </label> 
          </div> 
         </div> 
         <div class="form-group"> 
          <label for="customInput" class="col-sm-3 col-md-4 control-label">Item package:</label> 
          <div class="col-sm-9 col-md-8"> 
           <label class="radio-inline"> 
            <input type="radio" name="packageRadios" checked=""> Retail 
           </label> 
           <label class="radio-inline"> 
            <input type="radio" name="packageRadios"> OEM 
           </label> 
          </div> 
         </div> 
        </div> 
       </div> 
       <div class="row"> 
        <div class="col-md-6"> 
         <div class="form-group"> 
          <div class="col-sm-offset-3 col-md-offset-4 col-sm-9 col-md-8"> 
           <div class="checkbox"> 
            <label> 
             <input type="checkbox"> Override product description 
            </label> 
           </div> 
          </div> 
         </div> 
        </div> 
       </div> 
       <div class="form-group"> 
        <div class="col-sm-3 col-md-2 control-label"> 
         <label for="inputConditionNote">Product description:</label> 
         <div><i class="fa fa-arrows-h icon-success"></i> <span class="side-details text-sm text-details">max 4000 chars</span></div> 
        </div> 
        <div class="col-sm-9 col-md-10"> 
         <textarea class="form-control" id="inputConditionNote" name="inputConditionNote" rows="5"></textarea> 
        </div> 
       </div> 
       <div class="row"> 
        <div class="col-md-6"> 
         <div class="form-group"> 
          <label for="customInput" class="col-sm-3 col-md-4 control-label">Shipping:</label> 
          <div class="col-sm-9 col-md-8"> 
           <label class="radio-inline"> 
            <input type="radio" name="shippingRadios" checked=""> Default 
           </label> 
           <label class="radio-inline"> 
            <input type="radio" name="shippingRadios"> Free 
           </label> 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
     </section> 
     <section class="form-horizontal form-details-section"> 
      <header class="form-details-header"> 
       <h4 class="title-sm">Hazards and restrictions</h4> 
      </header> 
      <div class="form-details-body"> 
       <div class="form-group"> 
        <label class="col-sm-3 col-md-2 control-label">Hazards and restrictions:</label> 
        <div class="col-sm-9 col-md-10"> 
         <div class="form-group"> 
          <label class="col-sm-3 col-md-4 control-label">Shipping hazardous materials:</label> 
          <div class="col-sm-9 col-md-8"> 
           <label class="radio-inline"> 
            <input type="radio" name="materialsRadios" checked=""> Yes 
           </label> 
           <label class="radio-inline"> 
            <input type="radio" name="materialsRadios"> No 
           </label> 
          </div> 
         </div> 
         <div class="form-group"> 
          <label class="col-sm-3 col-md-4 control-label">Age 18+ verification:</label> 
          <div class="col-sm-9 col-md-8"> 
           <label class="radio-inline"> 
            <input type="radio" name="ageRadios" checked=""> Yes 
           </label> 
           <label class="radio-inline"> 
            <input type="radio" name="ageRadios"> No 
           </label> 
          </div> 
         </div> 
         <div class="form-group"> 
          <label class="col-sm-3 col-md-4 control-label">Choking hazard:</label> 
          <div class="col-sm-9 col-md-8"> 
           <div class="checkbox"> 
            <label> 
             <input type="checkbox"> Item contains small parts. 
            </label> 
           </div> 
           <div class="checkbox"> 
            <label> 
             <input type="checkbox"> Item is a small ball. 
            </label> 
           </div> 
           <div class="checkbox"> 
            <label> 
             <input type="checkbox"> Item contains a small ball. 
            </label> 
           </div> 
           <div class="checkbox"> 
            <label> 
             <input type="checkbox"> Item contains balloons. 
            </label> 
           </div> 
           <div class="checkbox"> 
            <label> 
             <input type="checkbox"> Item is a marble. 
            </label> 
           </div> 
           <div class="checkbox"> 
            <label> 
             <input type="checkbox"> Hazards and restrictions 
            </label> 
           </div> 
          </div> 
         </div> 
         <div class="form-group"> 
          <label class="col-sm-3 col-md-4 control-label">California proposition 65:</label> 
          <div class="col-sm-9 col-md-8"> 
           <div class="radio"> 
            <label> 
             <input type="radio" name="propositionRadios" checked=""> None 
            </label> 
           </div> 
           <div class="radio"> 
            <label> 
             <input type="radio" name="propositionRadios"> Item is a motherboard and contains chemicals know to the state California to cause cancer and reproductive toxicity. 
            </label> 
           </div> 
           <div class="radio"> 
            <label> 
             <input type="radio" name="propositionRadios"> Item is NOT a motherboard and contains chemicals know to the state California to cause cancer or reproductive toxicity. 
            </label> 
           </div> 
          </div> 
         </div> 
        </div> 
       </div> 
      </div> 
     </section> 
    </div> 
    <footer class="text-center"> 
     <div loading-indicator-btn> 
      <button type="button" class="btn btn-secondary btn-wide text-semistrong"><span>Save</span></button> 
     </div> 
    </footer> 
</div> 

이것이다 :이 내 템플릿 지시문입니다

module kz.controls.products.details { 
    'use strict'; 
    debugger;//First 
    import IDropDown = kz.controls.common.IDropDown; 
    import FilterItemModel = WebApi.Core.Models.Common.FilterItemModel; 
    import NewEggTabModel = WebApi.Core.Models.Products.Details.NewEggTabModel; 
    import NewEggListingSettingsModel = Kyozou.Model.Auctions.NewEgg.NewEggListingSettings; 


    class TabController { 
     public $scope: ng.IScope; 
     public details: INewEggDetailsTab; 
     public errorsNotifyService: kz.blocks.IErrorsNotifyService; 
     public dropdownsDataService: kz.services.IDropdownsDataService; 
     public newEggListingSettingsService: kz.services.INewEggListingSettingsService; 
     public config: kz.settings.IApiEndpointConfig; 


     private formName: string; 
     private conditionNoteIsVisible: boolean; 



     private multiselectSettings = { 
      dynamicTitle: false, 
      showCheckAll: false, 
      showUncheckAll: false, 
      scrollableHeight: '200px', 
      scrollable: true, 
     }; 
     private eventsFeedback = { 
      onItemSelect:() => { 


      }, 
      onItemDeselect:() => { 


      } 
     }; 
      private specificsPath: string[]; 

     static $inject = [ "$modal", "$route"]; 

     constructor(
      private $modal, 
      private $route: ng.route.IRouteService 
     ) { } 

     onDataLoaded() { 

      this.specificsPath = [this.config.getTypescriptPath('ts/controls/common/amazon-specifics.directive.js')]; 


      this.$scope.$watch(() => { 
       return this.details.isDirty; 
      }, (newValue: boolean) => { 
       if (newValue) { 
        this.$scope['newEggTabForm'].$setDirty(); 
       } else { 
        this.$scope['newEggTabForm'].$setPristine(); 
       } 
      }); 

      this.$scope.$watch(() => { 
       return this.$scope['newEggTabForm'] ? this.$scope['newEggTabForm']['$dirty'] : false; 
      }, (newValue: boolean, oldValue: boolean) => { 
       this.details.isDirty = newValue; 
      }); 


     } 

     loadProductSettings(templateId: number, amazonSettingsID?: number): void { 


     } 

     setAmazonProductType(value: FilterItemModel) { 


     } 

     setAmazonProductConditionType(value: FilterItemModel) { 

     } 

     setStrategyType(value: FilterItemModel) { 
        } 

     setShipsDomestically(value: FilterItemModel) { 
        } 

     setFulfillmentChannel(value: FilterItemModel) { 
        } 

     setFulfillment(value: FilterItemModel) { 

        } 


     getKeysFromStringList(stringList: string[], dictionary: { [id: number]: { id; label; }; }): { id; }[] { 
      stringList = stringList || []; 
      var items: { id; }[] = []; 
      for (var key in dictionary) { 
       for (var i = 0; i < stringList.length; i++) { 
        if (dictionary[key].label === stringList[i]) { 
         items.push({ id: key }); 
         continue; 
        } 
       } 
      } 

      return items; 
     } 

     getStringListFromKeys(keys: { id; }[], dictionary: { [id: number]: { id; label; }; }): string[] { 
      var items: string[] = []; 
      for (var i = 0; i < keys.length; i++) { 
       items.push(dictionary[keys[i].id].label); 
      } 
      return items; 
     } 

     updateAmazonSettings() { 
      this.details.isValid = this.$scope['newEggTabForm']['$valid']; 
      if (this.details.isDirty === false) { 
       this.errorsNotifyService.error('No changes!'); 
       return; 
      } 

      angular.forEach(this.$scope['newEggTabForm'].$error.required, (field) => { 
       field.$setDirty(); 
      }); 
      this.$scope['newEggTabForm'].$setDirty(); 

      if (this.details.isValid) { 
      } 
     } 

     searchCatalog(): void { 

      // this.details.searchCatalog(SearchCatalogTabEnum.Amazon, this.details.amazonListingSettingsModel.sellerId); 
     } 

     openLinkModal(): void { 

      //this.amazonCategoryService.getAmazonCategoryLink(this.details.amazonListingSettingsModel.templateId) 
      // .then(result => { 
      //  this.amazonCategoryLink = result; 
      //  this.modalInstance = this.$modal.open({ 
      //   templateUrl: this.config.getTemplatePath('ts/controls/common/amazon-category-link.modal.tpl.html'), 
      //   scope: this.$scope, 
      //   backdropClass: 'backdrop-fixed' 
      //  }) 
      // }) 
     } 

     cancelModal(): void { 


     } 

     disable() { 

     } 

     enable() { 


     } 
    } 

    class Directive implements ng.IDirective { 
     restrict = 'EA'; 
     controller = TabController; 
     controllerAs = 'vm'; 
     replace = true; 
     templateUrl: string; 
     scope = { 
      details: '=', 
     }; 

     constructor(errorsNotifyService, dropdownsDataService, newEggListingSettingsService, config: kz.settings.IApiEndpointConfig) { 
      debugger; 
      TabController.prototype.errorsNotifyService = errorsNotifyService; 
      TabController.prototype.dropdownsDataService = dropdownsDataService; 
      TabController.prototype.newEggListingSettingsService = newEggListingSettingsService; 
      TabController.prototype.config = config; 
      this.templateUrl = config.getTemplatePath('ts/controls/products/details/newEgg-tab.tpl.html'); 



     } 

     link(scope: ng.IScope, element: ng.IAugmentedJQuery, attributes: ng.IAttributes,controller: TabController): void { 
      debugger; 
      controller.$scope = scope; 
      controller.details = scope['details']; 
      controller.onDataLoaded(); 
     } 
    } 


    export interface INewEggDetailsTab extends kz.modules.products.details.IBaseTab { 
     productDetailsModel: WebApi.Core.Models.Products.ProductDetailsModel; 
     newEggListingSettingsModel: Kyozou.Model.Auctions.NewEgg.NewEggListingSettings; 
     newEggProductTypes: Array<FilterItemModel>; 
     newEggProductConditionTypes: Array<FilterItemModel>; 
     priceAdjustStrategyTypes: Array<FilterItemModel>; 
     newEggCategories: Array<FilterItemModel>; 
     newEggTabModel: NewEggTabModel; 
     enabled: boolean; 
     searchCatalog: (tab: SearchCatalogTabEnum, newEggSellerId: number) => void; 
     inTabView: boolean; 
    } 

    instance.$inject = [ 
     kz.Constants.Services.ErrorsNotifyService, 
     kz.Constants.Services.DropdownsDataService, 
     kz.Constants.Services.NewEggListingSettingsService, 
     kz.Constants.Services.ApiEndPoint 
    ]; 

    function instance(errorsNotifyService, dropdownsDataService, newEggListingSettingsService, config): ng.IDirective { 
     debugger; 
     return new Directive(errorsNotifyService, dropdownsDataService, newEggListingSettingsService, config); 
    } 

    angular 
     .module(kz.Constants.Modules.ProductsDetailsControlls) 
     .directive(kz.Constants.Directives.NewEggTab, instance); 
} 

:

내 지시어이다에서

<div class="tab-content" ng-repeat="tab in vm.tabsVisibility.newEggTabs" ng-if="vm.selectedTab == 'newegg-'+tab.newEggSellerId"> 
     <div oc-lazy-load="vm.lazyLoadParams"> 
      <div data-kz-newegg-tab data-details="vm.newEggDetailsTabs['newegg-'+tab.newEggSellerId]"></div> 
     </div> 
    </div> 

답변

0

당신의 코드 :

class Directive implements ng.IDirective

이것은 잘못되었습니다. 지시문 정의 함수가 new없이 호출되므로 class이 작동하지 않습니다. '지시문 링크 문제 문제를 해결하는 방법에 '단계 튜토리얼에 의해

+0

답변 해 주셔서 감사합니다. 지시어 정의 기능이란 무엇입니까? – Roysh

1

단계 :

1 단계. AngularJS에 표시 할 내용이 있습니까? 당신은 객체가 페이지에 rendred 할 데이터가 포함되어 있는지 확인해야

  • 검사 'vm.tabsVisibility.newEggTabs은'ng-if="vm.selectedTab == 'newegg-'+tab.newEggSellerId"

    'true'는
  • 체크하면 일부 데이터가있는 경우

    모두 괜찮 으면 2 단계로 진행하십시오.

단계 2. AngularJS는 내 속성을 이미 컴파일 된 디렉티브의 이름으로 인식합니까? 위에서 언급 한 바와 같이 당신이 AngularJS와가 알고있는 지침의 배열에서 찾을 수있을 것보다

당신의 지시자는 런타임 <div oc-lazy-load="vm.lazyLoadParams">에서 컴파일 된 경우.

내 지침의 이름은 무엇입니까? - 지시어 이름 정규화 AngularJS와시는 attrubite를 찾아 상수 'kz.Constants.Directives.NewEggTab'의 name = 'data-kz-newegg-tab'

ngAttrName = 'kzNeweggTab' 이상의 값은 'kzNeweggTab'해야 할 때 다음 지시문 이름

ngAttrName = directiveNormalize(name); 

로 끝납니다. 코드의 평화를 공유하지 않았기 때문에 추측 할 수 있지만 값의 철자가 틀리거나 AngularJS가 예상하는 것과 다른 경우 '링크'기능이 실행되지 않습니다. 난 당신의 코드에서 볼

당신이 사용하는 많은 장소가 'NewEggTab' 대신 'NeweggTab' 예의 :

  • 이름 = '데이터 KZ-뉴에 그 - 탭 '은 ngAttrName ='kzNeweggTab '
  • 입니다. 이름 ='데이터 -kzFrom here:

    각도가 요소의 태그를 정규화 및 요소 일치하는 지침을 결정하는 속성 명 : - 새로운 달걀 탭는

소스를 kzNewEggTab ''ngAttrName = 것 '. 대개 대/소문자를 구분하는 camelCase 정규화 된 이름 (예 : ngModel)으로 지시문을 참조합니다. 그러나 HTML은 대소 문자를 구분하지 않으므로 일반적으로 DOM 요소의 대시로 구분 된 속성 (예 : ng-model)을 사용하여 DOM의 지시문을 소문자 형식으로 참조합니다.

  1. 스트립 X- 및 요소/속성 앞에서 데이터 - 다음과 같이

    정규화 과정이다. 당신이 AngularJS와에게 통지 한 불가리아어 개발자 Minko Gechev 'Build Your own Simplified AngularJS in 200 Lines of JavaScript '에 의해 좋은 기사가있을 경우 최종에서 .. 낙타 표기법에

을, 또는 _로 구분 된 이름 - :

  • 은 변환합니다. 여기서 간단한 지시문을 사용하여 AngularJS에서 지시어가 어떻게 작동하는지 기본적인 아이디어 인 에 익숙해 질 수 있습니다.

    작업중인 프로젝트에 행운을 비네.

  • 관련 문제