I think you need to review your code design. The idea of having <script>
tag inside a ng-repeat
doesn't look best practice to me.
You could create simple directive
that could be placed inside the ng-repeat
. Every time one of the directives is instantiated by the loop you could run your function new primitives.orgdiagram.ItemConfig()
with all the parameters you need.
I've created something similar but instead of calling your function, I am printing on the console.
Please take a look at the code below or working example here (http://plnkr.co/edit/1J2Ep6DbfUiFDkL6TUAv?p=preview)
<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<script>
var myApp = angular.module('myApp', []);
myApp.controller('PostsCtrlAjax', ['$scope', '$http' ,function ($scope, $http) {
$scope.tasks = {
"data" : [
{
name: 'Task 01',
description: 'Task 01 Description',
url: 'http://www.basicprimitives.com/demo/images/photos/z.png'
},
{
name: 'Task 02',
description: 'Task 02 Description',
url: 'http://www.basicprimitives.com/demo/images/photos/z.png'
}
]
};
}]);
myApp.directive('adviser', [ '$compile', function ($compile) {
return {
restrict: 'A',
transclude: true,
replace: true,
scope: {
item : "="
},
link: function (scope, element, iAttrs) {
var template = '<button ng-click="createAdviser(item.name, item.description, item.url)">{{item.name}}</button>';
scope.createAdviser = function(name, description, url) {
// var adviser1 = new primitives.orgdiagram.ItemConfig(name, description, url);
var adviser = [name, description, url];
console.log(adviser)
}
element.html(template).show();
$compile(element.contents())(scope);
}
};
}])
</script>
</head>
<body>
<div ng-controller="PostsCtrlAjax">
<div ng-repeat="task in tasks.data">
<div adviser item="task"></div>
</div>
</div>
</body>
</html>
ng-repeat
. – Chandermani Oct 7 '13 at 10:21