Anguar JS 1.x How to create a directive with attributes

Anguar JS 1.x How to create a directive with attributes

File Name: directive-test2-2.js
var tes = angular.module("myApp", []);

tes.controller("AppCtrl"function () {
    var app = this;
    app.message = "Hello";
})

tes.directive("firstDirective"function () {

    return function (scopeelementattrs) {
        //console.log("Hello"); //Empty
        //console.log(scope.app.message);
        //element.text(scope.app.message);
        element.text(scope.app.message + " " + attrs.message);
    }

})

File Name : Session2-2.html
<html>

<head>
    <title>Directive</title>
</head>

<body>

    <div ng-app="myApp" ng-controller="AppCtrl as app">

        <div first-directive="" message="Mom!"></div>
        <div first-directive="" message="Dad!"></div>
        <div first-directive="" message="Jeshua!"></div>
        <div first-directive="" message="Jeremiah!"></div>

    </div>

    <script src="../node_modules/angular/angular.min.js"></script>
    <script src="directive-test2-2.js"></script>

</body>

</html>

Comments