這是cshtml的一個片段:
<div>
<button type="button" ng-click="recalcButton()">Recalc Button</button>
</div>
<div ng-controller="appealPartialController">
<div ng-include="'/Partials/appealsPartial.html'"></div>
</div>
單擊 recalcButton 時,我想重新加載 AppealPartialController 中的資料。任何檔案或 JS 代碼示例將不勝感激!
uj5u.com熱心網友回復:
因此,經過大量的谷歌搜索和一個好主意的仙女,我找到了一個利用angularJS 的內置 $scope 并從父級呼叫加載函式的解決方案。
$scope.$$childHead.$$nextSibling.loadAppealModel($scope.claimID);
uj5u.com熱心網友回復:
您可以使用共享引數。首先你創建一個這樣的服務:
import { Injectable, EventEmitter } from '@angular/core';
import { Subscription } from 'rxjs/internal/Subscription';
@Injectable({
providedIn: 'root'
})
export class SharedParamsService {
invokeFirstComponentFunction = new EventEmitter();
subsVar: Subscription;
constructor() { }
onUpdateEnv(key, val) {
var toEmit = [key, val]
this.invokeFirstComponentFunction.emit(toEmit);
}
}
現在您可以在單擊按鈕時發出一個變數,因此在您的組件中,在匯入 SharedParamsService 并在您的建構式中宣告私有 sharedParams: SharedParamsService 之后:
recalcButton(){
this.sharedParams.onUpdateEnv("btn", this.jobObj.name);
}
最后,在匯入 SharedParamsService 并在建構式中宣告私有 sharedParams: SharedParamsService 后要重新加載的組件中:
this.sharedParams.subsVar = this.sharedParams.
invokeFirstComponentFunction.subscribe((emitted) => {
if (emitted[0] == "btn") {
this.ngOnInit();
}
});
當然,如果您只有這個按鈕要檢查,您可以避免使用 key, val 方式,但使用這種方式您可以訂閱多個按鈕切換或其他變數。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/341619.html
