当我的模型scnListing
发生变化时我无法触发我的手表组,但是当它在手表中时它会触发......我的其他两个模型(chartTyp
,{{1} })在组中触发监视组,但scnListing中的更改不会...
yAxistm
---- EDIT -------
完整代码:
//this does work when scnListing changes
$scope.$watch('scnListing', function(model) {
$scope.modelAsJson = angular.toJson(model, true);
console.log("model: ", model);
}, true);
//this does not work when scnListing changes, but works when the other two do
$scope.$watchGroup(['yAxistm', 'chrtTyp', 'scnListing'], function(newval, oldval) {
console.log('yAxistm val: ', newval[0]);
console.log('chartTyp val: ', newval[1]);
console.log('scenarios: ', newval[2]);
});
这里也是标记中的内容:
cloudJumper.controller("comparisonReportsController", function($scope, $rootScope, Scenario, Rpt_scn_cost_v, Rpt_scn_app_count_v, Rpt_scn_appl_target_unnest_timeseries_ftprnt_v) {
var selected_scenarios = $rootScope.selected_scenarios;
console.info('Selected Scenarios: ', selected_scenarios); // for testing
$scope.myScenarios = Scenario.find();
$scope.scnListing =[]
function get_scns () {
return Scenario.find().$promise.then(function(response){
var scnList = response
var scnLables = {
"selected": null,
"lists": {
"List of Scenarios": [],
"Selected Scenarios": []
}
};
for(var i=0; i<response.length; i++) {
scnLables.lists["List of Scenarios"].push(response[i].scenario_desc);
};
console.log("scnLables: ", JSON.stringify(scnLables));
return scnLables;
});
};
get_scns().then(function(scnLables){
$scope.scnListing = scnLables;
});
// Scenarion Comparison Of Cost Line Graph
var scn_cst_chart_data = [];
var costByScn2 = []; // graph data
var cstScnLvl = [];
var cntScnLvl = [];
$scope.yAxistm = 'yr';
$scope.chrtTyp = 'multiBarChart';
// $scope.$watch('scnListing', function(newval, oldval) {
//
// console.log("model: ", newval);
//
// },true);
//
// $scope.dropCallback = function(event, index, item, external, type, allowedType) {
//
//
// console.log("dropped");
// };
$scope.$watchGroup(['yAxistm', 'chrtTyp', 'scnListing'], function(newval, oldval) {
console.log('yAxistm val: ', newval[0]);
console.log('chartTyp val: ', newval[1]);
console.log('scenarios: ', newval[2]);
//does stuff
});
});
答案 0 :(得分:0)
尝试从watchgroup中删除组,这将起作用
$scope.$watch(['yAxistm', 'chrtTyp', 'scnListing'], function(newval, oldval) {
console.log('yAxistm val: ', newval[0]);
console.log('chartTyp val: ', newval[1]);
console.log('scenarios: ', newval[2]);
},true);