I have the following angularjs directive:
app.directive("partnersInfoView", function ($http) {
return {
restrict: 'A',
link: function ($scope, element) {
$http.get("/home/PartnerInfoTab") // immediately call to retrieve partial
.success(function (data) {
element.html(data); // replace insides of this element with response
});
}
};
});
which basically goes to an MVC controller and returns a partial view
public ActionResult PartnerInfoTab()
{
return PartialView("../ManagePartners/PartnerInfoTab");
}
in the parent view i have the following declaration:
<div id="genericController" ng-controller="GenericController">
<div partners-info-view></div>
</div>
that is making use of the angular directive to render the partial view, so far everything works great. Inside of my angular genericController i have a scope variable:
$scope.Data = data;
where data it's a json object that comes as response from a Rest Service
Json Response e.g.
{[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
The issue im having is that i cannot bind the $scope.Data variable in the directive template:
<div id="PartnerInfoTab">
<div class="form-group">
<label class="col-md-2 control-label">Name</label>
<div class="col-md-8">
<input id="txt_name" class="form-control" type="text" ng-model="Data.firstName">
</div>
</div>
</div>
My question is, How do you pass the parent scope to the angular directive in order to be able to data-bind the elements in the partial view. What am i missing ??
Thanks in advance.