niisar
12/11/2014 - 1:49 AM

Setting Only a link() Function

Setting Only a link() Function

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="js/angular.js"></script>
    <script>
        myapp = angular.module("myapp", []);
        myapp.directive('userinfo', function () {
            var directive = {};

            directive.restrict = 'E'; /* restrict this directive to elements */

            directive.link = function ($scope, element, attributes) {
                element.html("This is the new content: " + $scope.firstName);
                element.css("background-color", "#ffff00");
            }

            return directive;
        })
        myapp.controller("MyController", function ($scope, $http) {
            $scope.cssClass = "notificationDiv";

            $scope.firstName = "nisar";

            $scope.doClick = function () {
                console.log("doClick() called");
            }
        });
    </script>
</head>
<body ng-app="myapp">
    <div ng-controller="MyController">
        <userinfo>This will be replaced</userinfo>
    </div>
</body>
</html>