[英]How to access unique injected dependency values outside of the function that required them in JavaScript
[英]Trying to access a injected dependency outside controller method
是否可以在其外部访问对控制器的注入依赖性?
function clienteCreateController(ClientesService, recuperarEndereco) { var vm = this; vm.pesquisarCep = pesquisarCep; } function pesquisarCep(cep) { recuperarEndereco.find(cep) .success(function(data) { parseEndereco(data).bind(this); }) .error(function(err) { // showAlertDanger(vm, 'Cep inválido.'); console.log(err); }); }
我通过单击按钮来调用该方法。
谢谢
我认为您不能在外部函数pesquisarCep
访问参数recuperarEndereco
。 因为在函数pesquisarCep
的执行上下文内,所以根本没有声明变量recuperarEndereco
。 与此JSFiddle相同: http : //jsfiddle.net/dLhmozf3/ 。 它报告错误:
function outsite () {
console.log('param: ' + param);
}
var f = function (param) {
var me = outsite;
me();
};
f();
您需要定义外部函数,例如: function pesquisarCep(cep, recuperarEndereco) { ...
并像pesquisarCep(cep, recuperarEndereco)
那样称呼它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.