2017-03-08 10 views
0

角度があり、このエラーが発生しました。角1.6型綴じ製エラー

キャッチされない例外TypeError:私は私がいくつかのJSONをフィルタリングするために使用し、親にこの機能を持っている親と子コンポーネントを持つサブパッケージ

に「$のCtrlキー」を検索する演算子「を」を使用することはできません一定の価値を得る。私は子コントローラの中で何をすべきかに悩まされているので、私はこの親関数を呼び出すことができ、子テンプレートからこれを呼び出すために何をする必要があるのか​​把握し始めていません。ここに私が持っているものがあります。

var myApp = angular.module('subPackages', ['ngMaterial', 'ngMessages']); 


(function (app) { 
    'use strict'; 

    app.component('appComponent', { 
     templateUrl: '../subpackages/templates/app-template.html', 
     controller: subAppController 
    }); 


    app.component('perfList', { 
     templateUrl: '../subpackages/templates/perf-list.templateV3.html', 
     controller: PerfListController, 
     bindings: { 
      contentJson: '<', 
      getGlobalContent: '&' 
     }, 
    }); 

})(myApp); 

function subAppController() { 

    this.currentStep = 1; 


    this.contentJson = 
    { 
     "id": "1", 
     "cart_method": "cartAdd", 
     "package": "69", 
     "page_title": "Subscriptions", 
     "page_header": "Choose a minimum of 3 performances\/events for guaranteed subscriber prices throughout the season.<\/br>\r\nStep 1: Choose your performances and price sections. Step 2: Indicate your seating preference.", 
     "add_btn_txt": "Add" 
    } 

    this.globalContentJson = [ 
      { "id": "1", "module": "subpackage", "item": "mobileNavText", "content": "Month Navigation" }, 
      { "id": "2", "module": "subpackage", "item": "allPerfText", "content": "All Performances" }, 
      { "id": "3", "module": "subpackage", "item": "pageTopText", "content": "BACK TO TOP" }, 
      { "id": "4", "module": "subpackage", "item": "cartSummaryText", "content": "Your Selections" }, 
      { "id": "5", "module": "subpackage", "item": "cartSummaryRemoveText", "content": "Delete" }, 
      { "id": "6", "module": "subpackage", "item": "continueBtnText", "content": "Continue" } 
    ]; 



    //Called from the template to get global content. 
    this.getGlobalContent = function (module, item) { 
     var globalContent = new contentProvider(this.globalContentJson); 
     var result = globalContent.get(module, item); 
     return result; 
    } 

} 

親テンプレート

<div class="container-fluid"> 
    <div class="cs-app-left row"> 
     <div class="pull-left"> 
      <label>{{$ctrl.contentJson.page_title}}</label> 
     </div> 
     <div class="cs-app-right pull-right">   
      <cart-summary 
      content-json="$ctrl.contentJson"> 

      </cart-summary> 
     </div> 
    </div> 

    <div class="cs-app-main row"> 
     <div> 
      <perf-list 
         ng-if="$ctrl.currentStep == 1" 
         content-json="$ctrl.contentJson" 
         get-global-content="$ctrl.getGlobalContent(module,item)" 
        > 

      </perf-list> 
     </div> 
    </div> 
</div> 

子コントローラ

function PerfListController() { 
this.$onInit = function() { 
    this.content = this.contentJson; 
    this.globalContent = this.getGlobalContent; 

    var cartAddEl = angular.element(document.querySelector('.cs-cartadd')); 
    var redirectEl = angular.element(document.querySelector('.cs-redirect')); 

    if (this.content.cart_method == "cartAdd") { 
     cartAddEl.removeClass('hidden'); 
     redirectEl.addClass('hidden'); 
    } else { 
     redirectEl.removeClass('hidden'); 
     cartAddEl.addClass('hidden'); 
    } 
    this.cart_method = this.content.cart_method; 

    this.test = this.globalContent("subpackage", "mobileNavText"); 
}; 
//Other Code Here 
} 
+0

ちょっと混乱していますが、ちょうどあなたがinitメソッドで呼び出すのであれば、なぜ子コントローラ内の関数が必要なのでしょうか?なぜそれにデータを渡すだけではないのですか? – tcrite

+0

申し訳ありませんが、ここにあなたをフォローしていません。子コンポーネントの中に関数を持っていく代わりに、子テンプレート内の親から関数を呼び出すだけでいいですか?再び、私は残念です。これは非常に新しいです。 – Marty

+0

親と子コントローラの両方でこの関数が必要なのだろうかと思います。親と子の両方の関数のデータを使って何かをしていますか? – tcrite

答えて

0

それを解決得ました。子テンプレートで関数を間違って呼び出していました。使用して終了しました

<span> 
    {{$ctrl.globalContent({module: "subpackage", item:"mobileNavText"})}} 
</span> 

クラスのアドバイスをいただき、ありがとうございます。

関連する問題