Helllo,
i want to pass the one value from controller to directive in angularjs. how would i pass the value and display it in directive .
in Html Section
in controller section my controller name is docontroller.
$scope.name = "world";
angular.element(document.querySelector('#carControls')).append($compile( mydirectivename as tag )($rootScope));
i have to pass my variable as well as controller in which i can get direct access in my directives it is my directive used in controller and appended to html in my directive section
myApp.directive('Controls', function ($compile, $rootScope, $timeout, $window) {
var linker = function (scope, element, attrs) {
alertr('name' + scope.name);
$timeout(function () {
scope.controlClass = 'fa fa-pause';
var ControlsTemplate =
'<button class="btn btn-default btn-sm margin-r-10 text-center"><i class="fa fa-backward"></i></button>'+
'<button ng-click="doPlayOrPause()" class="btn btn-default btn-sm margin-r-10 text-center"><i id="play-pause" ng-class="controlClass"></i></button>'+
'<button class="btn btn-default btn-sm margin-r-10 text-center"><i class="fa fa-forward"></i></button>'+
'<button ng-click="doStop()" class="btn btn-default btn-sm margin-r-10 text-center"><i class="fa fa-stop"></i></button>';
element.html(ControlsTemplate);
$compile(element.contents())(scope);
});
};
return {
restrict: "E",
replace: true,
link: linker
};
});
in return i passed controller :'docontroller bt i cant find my name in scope'