Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AngularJS An Introduction to Two-Way Data Binding Two-Way Binding: ngModelCtrl

David Karlsson
David Karlsson
4,180 Points

It says that console.log should be called within my render function, which it is.

I still have trouble understanding what exactly I'm supposed to log to the console. This is very unclear to me and after rewatching the video a couple of times, it's still not very clear. Sorry for the inconvenience.

app.js
angular.module('myApp', [])
.controller('myController', function($scope) {
  $scope.user = {
    name: 'Alex'
  };
})
.directive('myDirective', function () {
  return {
    require: 'ngModel',
    priority: 1,
    link: function ($scope, $element, $attrs, ngModelCtrl) {

      // YOUR CODE HERE
      ngModelCtrl.$render = function(){
        console.log($viewValue);
      }

    }
  }
});
index.html
<!DOCTYPE html>
<html ng-app="myApp">
<head>
  <title>Angular.js</title>
  <script src="js/angular.js"></script>
  <script src="app.js"></script>
</head>
<body ng-controller="myController">

  <p>Hello {{user.name}}</p>
  <input type="text" ng-model="user.name" />
  <div my-directive ng-model="user.name"></div>

</body>
</html>

3 Answers

You're super close. $viewValue is not a standalone variable. It is attached to the ngModelCtrl. So in referencing it, use dot notation to access that property from ngModelCtrl. Hint: console.log(ngModelCtrl.____________ )

David Karlsson
David Karlsson
4,180 Points

Thanks, that worked, sadly I have no idea how I was supposed to get to that conclusion. I'll keep doing the course and see if things start to clear up.

Jason Lewis
Jason Lewis
984 Points

This problem makes no sense and is very confusing of what is needed to complete the problem. Thank you for asking this question and thank you Riley for the hint!

David Karlsson
David Karlsson
4,180 Points

I'm sorry, do you mean I should have understood it without any problems? I guess I must have missed something in that case, sorry.

These hints are not helpful and are running my code in circles of deleting and readding.