0
採用可變我有2個指令:調用從孩子指令的功能和在父指令
指令A
具有$scope.originalData
變量,從HTTP請求獲取數據,並且還具有使用該功能變量:
$scope.findStepEducatByActId = function(act_id){
console.info('findfindStepEducatByActId',$scope.originalData);
if(angular.isDefined($scope.originalData.connections)){
angular.forEach($scope.originalData.connections[0].con_detail,function(value,key){
if(value.act_id_from == act_id){
return value.educategory_from;
}
if(value.act_id_to == act_id){
return value.educategory_to;
}
});
}
};
指令B
(被稱爲flowChart
)具有該功能傳遞給它在A
<flow-chart findStepEducatByActId="findStepEducatByActId(act_id)"></flow-chart>
的HTML文件模板
而且我也是在這個文件打印出來$scope.originalData
:{{originalData}}
指令B
被簡單地調用該函數:
angular.module('slmFlowClass').directive('flowChart', [function() {
return {
restrict: 'E',
templateUrl: 'scripts/modules/slmFlowClass/FlowClass.FlowChart.Template.html',
replace: true,
scope: {
findStepEducatByActId: '&'
},
link: function($scope, $element, $attrs) {
$scope.showNodeTooltip = function($event, node){
$scope.findStepEducatByActId('708663');
}
}
當我運行它,我得到一個日誌:findfindStepEducatByActId undefined
,但在HTML $scope.originalData
我可以看到這個變量包含的數據。 所以我的問題是,爲什麼當我從B
調用這個函數$scope.originalData
爲空?