AngularJS .component()中的输出函数('&')不起作用
Output function ('&') in AngularJS .component() not working
我正在使用angular 1.5.6组件。我试图使用输出绑定('&'),但不可能让它工作。我已经解决了我的问题。
index.html代码:
<body ng-app="MyApp">
<my-view></my-view>
</body>
我想使用输出绑定的组件的代码:
app.component('myInput', {
template: [
'<div class="form-group">',
'<label>{{$ctrl.label}}</label>',
'<input placeholder="{{$ctrl.placeholder}}" class="form-control" ng-model="$ctrl.fieldValue"/>',
'</div>'
].join(''),
controller: function() {},
bindings: {
label: '@',
placeholder: '@',
fieldValue: '=',
onUpdate: '&'
}
});
父组件的代码(输出绑定通过属性on-update完成):
app.component('myView', {
template: [
'<div class="container">',
' <h2>My form with component</h2>',
' <form role="form">',
' <my-input on-update="$ctrl.updateParam()" label="Firstname" placeholder="Enter first name" field-value=$ctrl.intermediaryData.firstName ></my-input>',
' </form>'
].join(''),
controller: function() {
var ctrl = this;
ctrl.userData = {
firstName: 'Xavier',
lastName: 'Dupont',
age: 25
};
ctrl.intermediaryData = {
firstName: ctrl.userData.firstName,
lastName: ctrl.userData.lastName,
age: 25
};
function updateParam(){
console.log("I have updated the component");
}
}
});
我的错,我忘了在输入组件中添加ng-change。我设法这样解决了这个问题:
app.component('myInput', {
template: [
'<div class="form-group">',
'<label>{{$ctrl.label}}</label>',
'<input ng-change="$ctrl.change()" placeholder="{{$ctrl.placeholder}}" class="form-control" ng-model="$ctrl.fieldValue"/>',
'</div>'
].join(''),
controller: function() {
var ctrl = this;
ctrl.change = function(){
ctrl.onUpdate();
}
},
bindings: {
label: '@',
placeholder: '@',
parentParam: '@',
fieldValue: '=',
onUpdate: '&'
}
});
相关文章:
- 监视函数从服务返回不起作用,但作用域函数起作用
- Ember Data DS.Model's set函数不起作用
- Javascript:If-then语句在函数中不起作用
- JavaScript链接在点击时不起作用;函数在页面加载时工作
- AngularJS指令部分应用的函数don'不起作用
- 为什么我的JavaScript堆栈排序函数不起作用
- 嵌套到另一个函数中的Fancybox函数;不起作用
- Javascript onchange()函数不起作用
- I'我试图在文本区域中进行特定的输入,调用特定的javascript函数,但没有成功;不起作用
- javascript函数调用不起作用
- 另一个Ajax函数触发的Ajax函数不起作用
- 从PHP调用JS函数不起作用
- 清除函数中if语句内部不起作用的间隔
- js函数堆栈传入变量,.hide()不起作用
- jQuery validate函数不起作用
- jQuery克隆函数在chrome中不起作用
- JS-窗口宽度函数不起作用
- 函数调用不起作用
- .hasClass 在 onclick 函数中不起作用,但删除和添加类函数可以
- javascript函数,该函数不起作用,但不会显示任何错误