Closed yanivefraim closed 9 years ago
I totally agree, looking forward to reviewing your PR
Hey, A small question regarding this feature - do you think I should leave the current directive with a mandatory ngModel, and add a new directive that uses isolated scope? If so, should I leave it in the save directive test-file? Another option is to add the isolated scope to the current directive and remove ngModel...
@yanivefraim hmmm, it may be useful to have both examples. With the addition of .isolateScope()
in version v1.2.3 perhaps a new file would be the cleanest way to present the differences in testing (isolateDirective.md
?). What pattern are you going to suggest developers use for testing isolate scope? One pattern I've seen is moving logic such as adding a $watch
scope into the directive controller so it can be more easily unit tested.
@daniellmb ok, a new file (isolateDirective.md) sounds cool. One thing we have to take into consideration is how those files (such as 'controllerAs.md') will look like on the main readme.md page. Regarding a test pattern - I uses isolated scope test like this:
var isolated = element.isolateScope();
expect(isolated.item).toBeDefined();
Not sure what did you mean when said: "adding a $watch scope into the directive controller" (??)
@yanivefraim Probably more of a TDD OCD edge-case, but for times when you want to unit test that a directive is adding a $watch as expected: http://stackoverflow.com/questions/17371836/how-to-unit-test-isolated-scope-directive-in-angularjs
I agree we may need to rethink how we present the patterns with more than one variant. Maybe something like this:
$scope
this
(aka the Controller As syntax)
I think that using an isolated scope is more common scenario than
ng-model
. I would add it to the scenario + not sure thatng-model
should be mandatory. (I am willing to add a PR here!)