Once user click on the Input field .. I want to get the ID of the input field & filter the Object & bind the data on the Popover window. But Scope is not getting updated from directive. Below are the code please let me know where i'm doing wrong
var app = angular.module('MyModule', []);
app.controller("TestController", function ($scope, $window) {
//$scope.ID = '0';
$scope.myObj = [{ "ID": 0, "Name": 'user0' }, { "ID": 1, "Name": 'user1' }, { "ID": 2, "Name": 'user2' }]
$scope.GetData = function () {
var match = $.grep($scope.myObj, function (e) {
return e.ID == $scope.myID
});
return match;
};
});
app.directive('popOver', function ($compile, $timeout) {
return {
restrict: 'A',
link: function (scope, el, attrs) {
$(el).bind('click', function () {
scope.$apply(function () {
scope.myID = attrs.popoverid ;
});
});
$(el).popover({
placement: 'bottom',
container: 'body',
trigger: "click",
content: $compile($('#popover-content').html())(scope)
});
}
};
});
<div ng-repeat="i in [0,1,2]">
<input style="background: transparent"
type="text"
pop-over
popoverid="{{i}}"
id="{{i}}"
class="form-control enterTime" data-html="true">
<br /><br />
</div>
<div class="bottom hide" id="popover-content">
<div class="arrow" style="left: 47%;"></div>
<div class="Bground-Project">
<table>
<tr>
<td>
{{GetData()}}
</td>
</tr>
</table>
<button type="button" ng-click="buttonClicked()">click me</button>
</div>
</div>