Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!

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

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

<!DOCTYPE html>
<html ng-app="treehouseCourse">
  <script src="js/angular.js"></script>
  <script src="app.js"></script>

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


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)