0
新角度和获取此错误。角度1.6 typeError与绑定
遗漏的类型错误:“在”运营商不能使用分包搜索“$ CTRL”
我有父母和孩子组成部分,我对父母这个功能,我用它来过滤一些JSON来获得一定的价值。我陷入了在子控制器中做什么,所以我可以调用这个父函数,甚至没有开始弄清楚我需要做什么来从子模板中调用它。这是我的。
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
}
有点困惑,为什么你需要在子控制器中的函数,如果你只是在init方法中调用它?为什么不把数据传递给它? – tcrite
对不起,没有关注你。你是说,而不是把功能放到子组件中,只需从子模板中的父项调用该功能?再次,我很抱歉。这是非常新的。 – Marty
我想知道如果你需要在父和子控制器中的功能。你是否在做父母和孩子的函数中的数据? – tcrite