我想从角度控制器发送$范围到一个JavaScript函数,但在调用我的JavaScript函数(teste2)$范围总是未定义。
我还需要传递的$ HTTP,咆哮和ngProgressFactory到我的javascript函数...
angular.module('geonosis').controller('ListagemPessoasController', function (DTOptionsBuilder, DTColumnBuilder, $http, $q, $scope, growl, ngProgressFactory, $window) {
$scope.progressbar = ngProgressFactory.createInstance();
var vm = this;
vm.dtOptions = DTOptionsBuilder.fromFnPromise(function() {
$scope.progressbar.start();
var defer = $q.defer();
$http({
method: 'GET',
url: 'http://localhost:8082/pessoa/3',
headers: {
'Authorization': '328316ed-41dd-491d-b362-d80ec55d5ebd'
}
}).then(function successCallback(response) {
defer.resolve(response.data);
$scope.progressbar.complete();
}, function errorCallback(response) {
$scope.progressbar.complete();
growl.error("<b>Erro ao consultar pessoas</b>", {});
});
return defer.promise;
})
.withLanguage({
sUrl: '//cdn.datatables.net/plug-ins/1.10.15/i18n/Portuguese-Brasil.json'
});
vm.dtColumns = [
DTColumnBuilder.newColumn('nome').withTitle('Nome').withOption('width', '40%').withClass('text-center'),
DTColumnBuilder.newColumn('categoriaPessoa').withTitle('Categoria').withOption('width', '25%').withClass('text-center'),
DTColumnBuilder.newColumn('cidade').withTitle('Cidade').withOption('defaultContent', 'não informada').withOption('width', '25%').withClass('text-center'),
DTColumnBuilder.newColumn(null).withTitle('').withOption('width', '10%').withClass('text-center').notSortable()
.renderWith(function(data, type, full, meta) {
return '<a class="btn btn-primary btn-sm" onclick="teste2(' + data.idPessoa + ')">' +
' <i class="fa fa-trash-o"></i></a>'
+
'<button class="btn btn-primary btn-sm" onclick="edit2(' + data.idPessoa + ')">' +
' <i class="fa fa-pencil-square-o"></i></button>';
})
];
});
function teste2(id, $scope){
console.log(scope); //ALWAYS UNDEFINED!!
}
如果我把睾丸中的角escope内,我收到:没有定义 “teste2””
你需要在'Controller'创建'teste2'方法来访问'$ scope' –
是阿甘,这就是问题所在。但我改变了我的所有代码,以遵循本教程:http://l-lin.github.io/angular-datatables/archives/#!/angularWayDataChange –
尝试控制器中的'$ scope.teste2 = teste2' –