Neu mit eckigen und bekommen diesen Fehler.Angular 1.6 typeError mit Bindung
Uncaught Typeerror: nicht ‚in‘ Operator kann für ‚$ ctrl‘ in subpackage
Ich habe einen Elternteil und ein Kind Komponente, wo ich diese Funktion auf dem Elternteil, das ich einige JSON filtern verwenden, um zu suchen bekomme einen bestimmten Wert. Ich bleibe stecken in was in der Kindersteuerung zu tun, damit ich diese Elternfunktion aufrufen kann und nicht einmal angefangen habe, herauszufinden, was ich tun muss, um dies aus der Kind-Vorlage aufzurufen. Hier ist was ich habe.
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);
Eltern
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;
}
}
Eltern Vorlage
<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>
Kind Controller
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
}
ein wenig verwirrt, warum brauchen Sie die Funktion in der Kind-Controller, wenn Sie es nur in der Init-Methode aufrufen? Warum nicht einfach die Daten weitergeben? – tcrite
Es tut uns leid, Sie nicht hier zu verfolgen. Wollen Sie sagen, anstatt die Funktion in die Child-Komponente zu bringen, rufen Sie einfach die Funktion von der Eltern in der Child-Vorlage auf? Nochmals, es tut mir leid. sehr neu dabei. – Marty
Ich frage mich, ob Sie die Funktion sowohl in der Eltern-und Kind-Controller benötigen. Machst du etwas mit den Daten von der Funktion in den Eltern und Kind? – tcrite