我有一个状态定义process_master.detail.new_detail,它具有用于引导选项卡的控制器。它是process_master_detail_ctrl的子控制器。
$stateProvider.state('process_master',
{
url: '/:lab/process_master',
templateUrl: 'partial/process_master/process_master.html',
controller: 'process_master_ctrl'
}).state('process_master.detail',
{
url: '/:seg/:mat/:sub_entity',
views:
{
detail:
{
templateUrl: 'partial/process_master/process_master_detail.html',
controller: 'process_master_detail_ctrl',
resolve:
{
lm_pm_factory: 'lm_pm_factory',
lm_pm_record: function(lm_pm_factory, $stateParams)
{
var seg = $stateParams.seg;
var mat = $stateParams.mat;
var sub_entity = $stateParams.sub_entity;
if (seg == 'add' || mat == 'add' || sub_entity == 'add' )
{
return ({data: {data: ''}});
}
return lm_pm_factory.getone(seg, mat, sub_entity);
}
}
}
}
}).state('process_master.detail.new_detail',
{
url: '/new_detail',
templateUrl: 'partial/process_master/process_master_new_detail.html',
controller: 'process_master_new_detail_ctrl',
})
父控制器中解析的lm_pm记录设置为范围变量:
$scope.lm_pm = lm_pm_record;
在工厂lm_pm_factory中,我有一个通用的数据源创建器,该创建器以json格式检索数据并根据传入的URL返回dataSource:
// Get the data and return the data source object
f.get_data_source = function(url)
{
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: url,
type: "put",
dataType: "json"
}
}
});
return dataSource;
};
我从工厂中的其他函数调用此函数,这些函数传递不同的url,例如:
f.get_bc_data_source = function ()
{
return f.get_data_source(domain_factory.getDomain(':8080') + '/api/get_bc_data_source');
};
一切正常,直到必须使用参数为止。我试图在工厂中使用seg参数调用函数,如下所示:
f.get_sc_data_source = function (seg)
{
return f.get_data_source(domain_factory.getDomain(':8080') + '/api/get_bc_data_source', seg);
};
我无法从子控制器(process_master_new_detail_ctrl)调用以将范围值发送到工厂:
$scope.sc_data_source = lm_pm_factory.get_sc_data_source($scope.lm_pm.seg);
如果我在子控制器中执行了console.log($ scope.lm_pm.seg),它将显示seg的值很好,但是如果我在工厂中执行了console.log(seg),则其值seg未定义。您是否不允许将子控制器中的继承范围变量值传递给工厂?