angularjs中的链接选项
Linking option in angularjs
每当窗口调整大小时,我都想更新一些表达式。下面是我的指示,展示了我的尝试。
脚本
var app = angular.module("myApp", []);
app.controller("validate", function($scope, $window) {
$scope.outp = "hello";
});
app.directive("responsive", function($window) {
return {
resterict: "AE",
link: function cLink(scope, element, attrs) {
console.log(element);
scope.widthe = ($window).outerWidth;
//scope.$watch("widthe",function(newValue, oldValue){
//scope.chnage = newValue;
//});
element.bind("resize", function() {
console.log("called");
scope.$apply();
});
}
}
});
HTML
<body ng-app="myApp">
<div ng-controller="validate" responsive>
<div style="border:solid;width:500px;height:500px;">
<div>present width is {{width}}</div>
<div>{{chnage}}</div>
<button id="clicks">click me</button>
</div>
</div>
</body>
使用上面的代码,我无法将resize事件和元素绑定。每当调整窗口大小时,我都要更新宽度。你能帮我找出代码重构建议的解决方案吗。
如有帮助,不胜感激。提前感谢!!
您需要在指令链接中使用window.onresize
函数,然后高度更改逻辑将位于其中,但如果您想以角度方式进行操作,则需要使用与window
相同的angular的$window
API。
指令
app.directive("responsive", function($window) {
return {
resterict: "AE",
link: function cLink(scope, element, attrs) {
console.log(element);
scope.width = ($window).outerWidth;
//scope.$watch("widthe",function(newValue, oldValue){
//scope.chnage = newValue;
//});
angular.element($window).bind('resize', function() {
console.log("called");
scope.$apply();
});
}
}
});
希望这能对你有所帮助。谢谢
相关文章:
- 根据选项卡内部的文本链接中的哈希ID动态选择jqueryUI选项卡
- 在新选项卡中打开链接,但不使用_blank方法
- 打开选项卡中的链接
- JQuery-停止手风琴链接关闭所有选项卡
- 文本链接可更改引导程序选项卡
- <中的链接;选择>下拉选项
- 如何禁用鼠标中键单击超链接以在新选项卡或新窗口中打开
- 链接到手风琴中的另一个选项卡,嵌入的链接将不起作用
- 如何在新选项卡中打开链接以及在当前选项卡中重定向
- 表单上预先选择的选项取决于您的链接'We’’’’来自
- 如何超链接在新选项卡中打开并携带一些变量的选择标记
- 如何防止iframe中的链接在新选项卡中打开
- 单击我网站中的链接时打开新选项卡,保持当前选项卡处于活动状态
- 打开除域之外在新选项卡中打开的所有外部链接
- 单击链接时添加另一个选项
- 如何使用角度材质应用选项卡链接波纹
- 谷歌地图点击链接/选项卡更改标记位置地图
- 如何在分页期间链接回特定的jquery ui选项卡
- 选项卡中的a href链接没有执行任何操作
- 提交表单的可能性(左-/中-/在新选项卡或窗口中打开-)单击html链接