0
我有点新的角度。我的角度不工作的指令
我希望每当文档宽度变化时都有一个侦听器。
所以首先我决定增加一个$表是这样的:
$scope.$watch(function(){
return $window.innetWidth;
}, function(n, o){
console.log(n);
console.log(o);
});
但它只能在页面加载,而不是调整。
于是我决定写这样的指令:
app.directive('watchWidth', [function(){
return {
restrict: 'A',
link: function(scope, element) {
element.style.display = 'none';
$scope.$watch(function() {
return element.innerWidth;
}, function (n,o) {
console.log(n);
console.log(o);
});
}
};
}]);
并添加指令到我的NG-观点:
<div watchWidth ng-view class="main-wrapper"></div>
但没有工作,在控制台没有错误,我不知道我该怎么做!
请帮忙吗?
你是否看到这篇文章http://stackoverflow.com/questions/23044338/window-resize-directive? – aSoler
试试这个:'clientWidth'而不是'innerWith' –
或者用jquery:'$(element).innerWidth()' –