Angular: ng-repeat scope - 14410993

http://angularjs.org/

by scriptstar

HTML

<div ng-controller="MyCtrl">
    <div ng-repeat="line in lines">
        <div class="preview">{{line.text}} {{$index}}</div>
    </div>
    <div ng-repeat="line in lines">
        <!-- typing here should auto update it's preview above -->
        <input ng-model="line.text" />
        <!-- many other fields here that will also affect the preview -->
        <button ng-click="addChoice()">Add</button>
    </div>{{lines}}</div>

JavaScript

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

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function MyCtrl($scope) {
    $scope.lines = [{
        text: ''
    }];
    $scope.addChoice = function () {
        $scope.lines.push({});
    };
}