我有一个问题。我正在使用Angular localStoragee模块来存储设置,这些设置是我在控制器中通过以下方式设置的:
localStorageService.set('localStorageKey','Add this!');
它工作得很好,但是如何查看localStorageKey指令中的更改,该更改将其值作为参数?
我尝试了类似的东西:
.directive('fooBar', function(localStorageService){
var linker = function(scope, element, attrs){
var unit = localStorageService.get('localStorageKey');
$watch('unit', function(){
console.log(unit);
});
}
return {
restrict: 'AE',
scope: {
value: '@dataValue'
},
replace: true,
link: linker
}
});
但是,没有运气,我认为我不能看这样的变量。我怎么解决这个问题?
谢谢。
这应该工作:
$scope.$watch(function() {
return localStorageService.get('localStorageKey');
}, function(value) {
console.log(value);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句