I have a directive called templates, code for templates, as shown below.
var templates = function($compile,$parse){ var directive = { restrict: 'EA', replace: true, link: link }; return directive; function link(scope, element, attrs) { scope.name = "testName"; var isHtmlCompiled = false; } }; angular.module('templateModules', []) .directive('templates', templates);
This is mainly used to compile html code and display it. But for a better understanding of the issue, I do not use it for this purpose in this example. The app.js file looks below
angular.module('ui.bootstrap.demo', ['ui.bootstrap','templateModules']); angular.module('ui.bootstrap.demo').controller('AccordionDemoCtrl', function ($scope) { $scope.oneAtATime = true; $scope.groups = [ { title: 'Dynamic Group Header - 1', content: 'Dynamic Group Body - 1' }, { title: 'Dynamic Group Header - 2', content: 'Dynamic Group Body - 2' } ]; $scope.items = ['Item 1', 'Item 2', 'Item 3']; $scope.addItem = function() { var newItemNo = $scope.items.length + 1; $scope.items.push('Item ' + newItemNo); }; $scope.add = function(){ alert($scope.name); } $scope.status = { isFirstOpen: true, isFirstDisabled: false }; });
Index.html uses an accordion as shown below.
<!doctype html> <html ng-app="ui.bootstrap.demo"> <head> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js"></script> <script src="//angular-ui.imtqy.com/bootstrap/ui-bootstrap-tpls-0.13.1.js"></script> <script src="app.js"></script> <script src="template.js"></script> <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div ng-controller="AccordionDemoCtrl"> <accordion close-others="oneAtATime"> <accordion-group heading="Static Header, initially expanded" is-open="status.isFirstOpen" is-disabled="status.isFirstDisabled"> This content is straight in the template. </accordion-group> </accordion> <accordion close-others="oneAtATime"> <accordion-group heading="DYnamic" is-open="status.open" is-disabled="status.isFirstDisabled"> <div templates="something"></div> <button ng-click="add()">Add</button> </accordion-group> </accordion> </div> </body> </html>
The problem I am facing is that I cannot get the scope.name value from the template in AccordionDemoCtrl. Is there any way to get this value in AccordionDemoCtrl?
robin source share