scope test

by cm0s

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js"></script>
<div ng-app="app">
    <div ng-controller="AppCtrl">
        <mytext text-model="text"></mytext>
    </div>
</div>
<script type="text/ng-template" id="temp1.html">
    < p > hello0 < /p>
</script>

JavaScript

angular.module('app', [])
    .controller('AppCtrl', function ($scope, $http) {

})
    .directive('mytext', function () {
    return {
        restrict: 'E',
        scope: {
            textModel: "="
        },
        template: '<p ng-repeat="item in items"><a ng-click="warn(item)">WARN</a></p>',
        link: function (scope, element, attrs) {

        },
        controller: function ($scope) {
            $scope.items = ['hello', 'world'];
            $scope.warn = function (item) {

                alert(item)
            }
        }

    }
});