0
親コンポーネントを登録し、親更新が呼び出されたときにその子に固有の情報を提供するコンポーネントを作成しようとしています。コンポーネントを属性として作成できますか?
親:
angular
.module('app')
.component('parentComponent', {
templateUrl: function ($attrs) {
return '/Components/Component/template.cshtml';
},
bindings: {
api: "=",
},
controller: controller
});
function controller() {
var vm = this;
vm.subscribedApis = [];
vm.$onInit = function() {
vm.api.register = register;
vm.api.update = update;
vm.api.performOperation = performOperation;
};
function update() {
vm.subscribedApis.forEach(function (api) {
api.update();
});
}
function register(api) {
vm.subscribedApis.push(api);
}
function performOperation(viewValue){
//do something given the childs value
}
子:
angular
.module('app')
.component('childComponent', {
require: ['^parentComponent', 'ngModel'],
bindings: {
parentApi: "<",
},
link: function (scope, element, attrs, controller) {
controller.getViewValue = function() {
return ngModel.$viewValue;
}
},
controller: childController
});
function childController() {
var vm = this;
vm.$onInit = function() {
vm.api = {};
vm.api.update = update;
vm.parentApi.register(vm.api);
update();
};
function update() {
var tag = filterTagApi.performOperation(vm.getViewValue());
}
私の問題は、私はこの
<input type="text" id="title" class="form-control input-sm"
ng-model="search.parameters.title" autofocus
child-component parent-api="parentApi" />
<select class="form-control input-sm" ng-model="search.parameters.typeId"
ng-options="lookup.id as lookup.lookupValue for lookup in lookups.typesOfSomething"
child-component parent-api="parentApi">
<option value="" selected>All</option>
</select>
のような子タグを使用したいということですが、ジェネリックで行うことが、このことが可能ですchildモデルを含む異なる要素にアタッチすることができますか、あるいは私は別のアプローチを見つける必要がありますか?