Created
December 11, 2014 01:48
-
-
Save niisar/b002de223dbd543e19a2 to your computer and use it in GitHub Desktop.
compile() and link() Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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.compile = function (element, attributes) { | |
| element.css("border", "1px solid #cccccc"); | |
| var linkFunction = function ($scope, element, attributes) { | |
| element.html("This is the new content: " + $scope.firstName); | |
| element.css("background-color", "#ffff00"); | |
| } | |
| return linkFunction; | |
| } | |
| return directive; | |
| }) | |
| myapp.controller("MyController", function ($scope, $http) { | |
| $scope.firstName = "nisar"; | |
| }); | |
| </script> | |
| </head> | |
| <body ng-app="myapp"> | |
| <div ng-controller="MyController"> | |
| <userinfo>This will be replaced</userinfo> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment