Angular.js: so ändern Sie die div-Breite basierend auf Benutzereingaben

Ich habe ein input-Feld nimmt den Wert für die div-Breite.
Mit angular.js, Wie kann man ändern, div Breite abhängig von einer Benutzereingabe?
Ich habe folgenden code implementiert nachdem er diese Geige.http://jsfiddle.net/311chaos/vUUf4/4/

Markup:

 <input type="text" id="gcols" placeholder="Number of Columns" ng-model="cols" ng-change="flush()"/>

<div getWidth rowHeight=cols ng-repeat="div in divs">{{$index+1}} aaaaaa</div>

controller.js

var grid = angular.module('gridApp', []);

grid.controller('control', ['$scope', function ($scope) {

    /* code for repeating divs based on input*/
    $scope.divs = new Array();
    $scope.create=function(){ //function invoked on button's ng-click
            var a = $scope.cols;
            for(i=0;i<a;i++)
            {
                $scope.divs.push(a);
            }
            alert($scope.divs);
        };


}]);

grid.directive('getWidth', function () {
    return {
        restrict: "A",
        scope: {
            "rowHeight": '='
        },
        link: function (scope, element) {

            scope.$watch("rowHeight", function (value) {
                console.log(scope.rowHeight);
                $(element).css('width', scope.rowHeight + "px");
            }, false);
        }
    }
});

function appCtrl($scope) {
    $scope.cols = 150;   //just using same input value to check if working


}

UPDATE
Mein oberstes Ziel ist es, Breite, div. Wenn ich Anrufe, inline-CSS, wie ich das erreichen, was ich will.

<div get-width row-height="{{cols}}" ng-repeat="div in divs" style="width:{{cols}}px">{{$index+1}} aaaaaa</div>

Aber das wäre nicht immer effizient, wenn die Anzahl der divs geht hoch. Also nochmal die Frage bleibt, wie dies zu tun ist über die Winkel-Skript?

InformationsquelleAutor Sujit | 2014-01-03

Schreibe einen Kommentar