quickmock
quickmock copied to clipboard
$scope is not available on a directive until after first call to $compile()
.$scope
needs to be added to the directive object when quickmock()
is initially called, rather than during the .$compile()
phase, so that the scope properties can be modified before the compile happens.
Right now this requires a dummy call to .$compile()
so that the .$scope
first shows up:
var directive = quickmock({
providerName: 'myDirective',
moduleName: 'myModule',
html: '<div my-directive></div>'
});
// directive.$scope is undefined here
directive.$compile();
// directive.$scope is now defined
directive.$scope.key = "value";
// can now use `key` property on scope
directive.$compile('<div my-directive some-property="key"></div>');
What we need is the ability to do this:
var directive = quickmock({
providerName: 'myDirective',
moduleName: 'myModule',
html: '<div my-directive some-property="key"></div>'
});
directive.$scope.key = "value";
directive.$compile(); // this will now use the scope's `key` value during compile process
Yeah, that looks good. Or something like:
var directive = quickmock({
providerName: 'myDirective',
moduleName: 'myModule',
scope: POJOWithPropertiesThatAreMappedOntoScope,
html: '<div my-directive some-property="key"></div>'
});
directive.$compile();
Oh okay. I see. Just do like a angular.extend(newScope, configScope)
to merge all the properties from the config scope value onto the scope that is created by quickmock. I think I'll add both ways of doing it :)