2

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

asked Dec 12, 2014 at 15:52
2
  • 7
    $scope = {}; - what? Commented Dec 12, 2014 at 15:54
  • 3
    @tymeJV thanks for pointing that out.. mustve put it in accidently when making the controller.. the longer you stare at these things the more normal they look. Commented Dec 12, 2014 at 15:55

1 Answer 1

5

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.