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 Extending Inputs Extending Inputs: Optional require

problem with the conditional statement?

The error says I should check that the conditional is set up correctly, but I can't find any mistake. I used the ! operator to check for an undefined ngModelCtrl, with a direct return if that's the case. Help!

app.js
angular.module('treehouseCourse', [])
  .directive('sometimesTwoWay', function() {
    return {
    require: '?ngModel',
      link: function($scope, $element, $attrs, $ngModelCtrl) {
        if (!ngModelCtrl) {
          return;
        }

        console.log('my model', ngModelCtrl);

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

  <sometimes-two-way ng-model="course.description"></sometimes-two-way>

</body>
</html>

2 Answers

Lukas Smith
Lukas Smith
4,026 Points

Maybe You require: '?ngModel', and the rest of code You have ngModelCtrl, So try to chnage require: '?ngModelCtrl' if i am wrong ,sorry

Take the $ off of the $ngModelCtrl - link: function($scope, $element, $attrs, ngModelCtrl)