Angular directive test

by paos

HTML

<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://code.angularjs.org/1.0.0/angular-1.0.0.js"></script>
<div ng-controller="Ctrl1">
    <h3>Title</h3><br/>
    <input ng-model="inputdata.title">

    <h3>Isolated scope</h3>
    <div ng-repeat="i in [1]">
        <button ng-update1="inputdata.title">click to set title to Button 1 (doesn't work)</button>
        <button ng-update2="inputdata.title">click to set title to Button 2</button>
    </div>
</div>

CSS

.selected {
    background-color: #ff0000;
}

JavaScript

var app = angular.module('myApp', []);
app.directive('ngUpdate1', function() {
    return function(scope, element, attrs) {
        element.bind('click', function() {
            scope.$apply(function() {
                scope[ attrs.ngUpdate1 ] = "Button 1";
            });
        });
    };
});
app.directive('ngUpdate2', function() {
    return function(scope, element, attrs) {
        element.bind('click', function() {
            scope.$apply(function() {
                scope.inputdata.title = "Button 2";
            });
        });
    };
});

function Ctrl1($scope) {
    $scope.inputdata = {title:"test"};
}