ejemplo clase 4 - Watch Comp

by scyrizales

HTML

<div ng-app="" ng-controller="Ctrl1">
    <input type="text" ng-model="items[0].texto" />
    <div ng-repeat="i in items">
        {{ i.texto }}
    </div>
    <br>{{prueba}}
</div>

JavaScript

function Ctrl1($scope){
    var c;
    $scope.items = [
        {valor: 1, texto: "a"},
        {valor: 2, texto: "b"},
        {valor: 3, texto: "c"}
    ];
    $scope.prueba = "";
    function activarW() {
    c = $scope.$watch("items", 
        function(newV, oldV){
            alert(newV);
            c();
    }, true);
    }
    activarW();
    c();
}