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 trialeric francis
5,705 PointsWhy would a directive want to optionally require the NgModelController -- when it really is requiring the ngModel?
Q: Set the 'sometimesTwoWay' directive up to optionally require the NgModelController.
A: require: '?ngModel'
Why is the answer not 'require: "?ngModelController"' ?
angular.module('treehouseCourse', [])
.directive('sometimesTwoWay', function() {
return {
// YOUR CODE HERE
require: '?ngModel'
}
});
<!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>
5 Answers
Bryan Knight
34,215 PointsThe require property tells Angular that our directive requires the controller of another directive. In this case, we want to use the ngModel controller
Kristopher Van Sant
Courses Plus Student 18,830 PointsI'm not quite sure how to answer this so I hope someone can answer your question more clearly for you soon! But have you looked at angular's documentation for this yet? Hopefully it can help clear up the differences between ngModel and NgModelController.
https://docs.angularjs.org/api/ng/directive/ngModel
https://docs.angularjs.org/api/ng/type/ngModel.NgModelController
Kerry Rosado
14,368 PointsAccording to the angular documentation:
The ngModel directive binds an input,select, textarea (or custom form control) to a property on the scope using NgModelController, which is created and exposed by this directive.
Adam White
10,571 PointsCould someone please tell me the exact answer for this? I can't get my code to pass. Thanks.
Jazmine Stevenson
2,303 Pointsrequire: '?ngModel'
anduelpitushi
6,993 PointsJust this :
require : '?ngModel'