Javascript 自适应AngularJS指令

Javascript 自适应AngularJS指令,javascript,jquery,css,angularjs,adaptive-design,Javascript,Jquery,Css,Angularjs,Adaptive Design,以下是我们的jQuery代码: $(document).ready(function(){ $(window).on("load resize", function(){ if ($(window).width()<=960){ $(".myDirective").css("flex-direction", "column") } else{ $(".myDirective").css(

以下是我们的jQuery代码:

$(document).ready(function(){
    $(window).on("load resize", function(){
        if ($(window).width()<=960){
            $(".myDirective").css("flex-direction", "column")
        }
        else{
            $(".myDirective").css("flex-direction", "row")
        }
    })
});

但是如何添加条件呢?

在html中,将此
windowWidth
指令应用于您已设置为
.myDirective
类的元素

Ex. <p class="myDirective" window-width></p>


app.directive('windowWidth', function($window) {
    return {
        restrict: 'A',
        link: function(scope, $element) {
            scope.$watch(function() {
                if($window.width < 960) {
                    $element.css("flex-direction", "column");
                } else {
                    $element.css("flex-direction", "row");
                }
            })
        }, 
    }
});
Ex.

应用程序指令('windowWidth',函数($window){ 返回{ 限制:“A”, 链接:功能(范围,$element){ 范围$watch(函数(){ 如果($window.width<960){ $element.css(“弹性方向”、“列”); }否则{ $element.css(“弹性方向”、“行”); } }) }, } });
Ex. <p class="myDirective" window-width></p>


app.directive('windowWidth', function($window) {
    return {
        restrict: 'A',
        link: function(scope, $element) {
            scope.$watch(function() {
                if($window.width < 960) {
                    $element.css("flex-direction", "column");
                } else {
                    $element.css("flex-direction", "row");
                }
            })
        }, 
    }
});