This is a typical case for a directive.
app.directive("name", function() {
return {
restrict: "A",
templateUrl: "someTemplate.html",
scope: {
someValue: "="
},
controller: function($scope) {
$scope.result = $scope.someValue.a + $scope.someValue.b;
}
};
});
Use it as:
<div ng-controller="ParentController">
<!-- Include #1 -->
<div my-template some-value="container.someA"></div>
<!-- Include #2 -->
<div my-template some-value="container.someB"></div>
</div>
You will have to pay attention to the isolated scope, it does NOT inherit stuff from the parent scope; therefore you will have to pass any data that you want in the directive, just like the scope: { someValue: "=" }
.