2
\$\begingroup\$

In my code, when the index is 0, I am supplying the second template which contains the word as arif. With the rest I am supplying the first template which doesn't have the word arif.

I got this result as a result of a posted question, but I am not satisfied with it because of its length.

// Code goes here
"use strict";
angular.module('tcpApp', [])
.controller('MainCtrl', function($scope) {
  $scope.appNames=[{title:'titre1'},
                   {title:'titre2'},
                   {title:'titre3'}];

})
.directive('programName', function ( $compile ) {
        return {
            restrict    : 'AE',
            replace     : true,
            scope       : {
                            name:'@',
                            index:'@'
                        },

            link        : function (scope, element, attr) {
                            scope.callMe = function () {
                                console.log($(element).prop('class'));
                            }

                            var getTemplate = function( index ) {
                              return Number(index) ? '<h2 class="que t{{index}}" ng-click=callMe()>{{name}}</h2>' : '<h2 class="que t{{index}}" ng-click=callMe()>{{name}}arif</h2>';
                             }

                             element.html(getTemplate(scope.index));

                            $compile(element.contents())(scope);
                        }
        }
    })

Live Demo to Play

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.