4
我想使用我的page.controller中的一個組件的功能 首先,我不知道它是否可能?第二,如果可能的話,我該怎麼做?如何在AngularJS的頁面控制器中使用Component中的函數?
這裏我有component.controller稱爲checkStatus
,我要執行它裏面的功能,因此我ng-disabled
變成false
,我可以點擊SAVE
按鈕。
testComponent.component.js:
export default {
template: temp,
controller: myComponentController,
controllerAs: 'vm',
bindings: {
popupMsg : '&'
}
};
function myComponentController() {
'ngInject';
this.popupMsg = function() {
alert("It is working!");
this.checkStatus();
};
this.checkStatus = function() {
this.mustPass = true;
};
}
myPage.controller.js:
export class MyPageController {
constructor() {
'ngInject'
...
}
save() {
...
}
}
myPage.html下:
<form>
<test-component mandatory="vm.popupMsg()"> </test-component>
<div>
<button type="submit" ng-click="vm.save()" ng-disabled="!vm.mustPass"> Save </button>
</div>
</form>
我嘗試過,但它並沒有在所有的工作。永不改變爲'真實' – GeoCom
[更新的重擊](https://plnkr.co/edit/phLwjTo0vCYc2Ds9V35e?p=preview) – LT56