Ligações à diretiva com escopo Isolar às vezes não estão no escopo
Então eu tenho umdiretiva comisolar escopo e umcontrollerAs padronizar.
var directive = {
restrict: 'E',
scope: {
something: '='
},
templateUrl: './App/directiveTemplate.html',
controller: directiveController,
controllerAs: 'vm',
bindToController: true
}
e no controlador, inicio com uma chamada para um serviço REST usando$ http isso retorna uma promessa.
function directiveController(someService) {
var vm = this;
// Here vm.something is defined and bound to the appropriate model set where the directive is used
init()
function init() {
return someService.getProducts()
.then(productsReady);
function productsReady(response) {
vm.products = response;
//find product using vm.something
// here vm.something is undefined
return vm.products;
}
}
O problema é que, se eu interromper antes doinit()
métodovm.something
é definido como deveria ser, mas noproductsReady
função é indefinida.
Esse é um comportamento normal? A promessa está resolvendo o código em um escopo diferente?