I have a nested controller inside an ng-repeat as shown below. My problem is that my scope variables aren't binding, and the button doesn't reach the scope function either.. I have a controller set up and have the values assigned, it initializes and runs through fine but after this I am not presented with any values in the view.
<div ng-repeat="field in model.fieldData | filter:filterFn">
<div class="panel-heading">
.....
</div>
<div class="panel-body">
<div ng-controller="commentsCtrl">
<p>{{field.Id}}...{{model.text}}</p>
<button type="button" ng-click="createComment()">New</button>
</div>
</div>
</div>
angular.module('main').controller('commentsCtrl', [
'$scope', '$modal', 'connectionService', 'fieldService',
function ($scope, $rootScope, $http, $modal, connectionService, fieldService) {
$scope = {};
$scope.model = {};
$scope.model.text = "test for view";
$scope.createComment = function(){
...this never gets hit
};
}
]);
Edit-Solved: I have declared $scope = {} which has reset my whole scope.. fantastic
1 Answer 1
You are replacing the Angular $scope object, and consequently the behavior when you write:
$scope = {};
Remove that line and it will work.
answered Dec 12, 2014 at 15:58
lante
7,3924 gold badges39 silver badges59 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
$scope = {};- what?