在本例中改變範圍對象我有三個範圍中的對象依賴於其他範圍可變
$scope.themes = [
{
name: 'Theme 1',
backgroundColor: '#000000',
},
{
name: 'Theme 2',
backgroundColor: '#FFFFFF',
},
];
$scope.theme = {
name: 'Default Theme',
backgroundColor: '#000000',
};
$scope.config = {
canvas: {
fill: $scope.theme.backgroundColor,
},
elements: [
{
name: 'Circle',
width: 200,
height: 1000,
fill: $scope.theme.backgroundColor
},
]
};
一種ng-select
更新的$scope.theme
(使用$scope.themes
作爲ng-options
)的值。當$scope.theme
的變化,我想更新的$scope.config
,其中的某些屬性取決於$scope.theme
值的值。
$scope.config
有一個$watch()
通過一個指令在視圖中對元素進行更改,因爲可以通過界面更改一些編輯屬性。
當$scope.theme
更改時,如何觸發更新到$scope.config
以觸發我的$watch
?
(值得一提的是,以上是$scope.config
,那裏有內config.elements
很多項目的多刪節版。)
你是否意識到你根本不需要任何$ watch,因爲你可以使用對象引用? – dfsq
使用引用來利用繼承。象:'$ scope.theme = $ scope.themes [0]'...'$ {scope.config someProperty:$ scope.theme.propertyName}' – charlietfl