Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
ANgularJS binding not working. while calling an angularjs function from javascript function

I am calling an angularjs function from an javascript function. from javascript function I am passing a variable and assing the variable to $scope.usersName. But the value is not changing.

Below is the code that I have written

<!DOCTYPE html>
<html data-ng-app="javaScript">
<head>
<meta charset="ISO-8859-1">
<title>Call AngularJS function using JavaScript</title>
<script
    src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script type="text/javascript">
    var serviceModule = angular.module('javaScript', []);   
    serviceModule.controller('javaScriptController', function($scope) {
        $scope.javaScriptCallAngular = function(value) {
            $scope.usersName = value;
        };
    
    }); 
    function javaScriptCall(value){
        var scope = angular.element(document.getElementById('idForJS')).scope();
        scope.javaScriptCallAngular(value);
    }   
</script>
</head>
<body id="idForJS" data-ng-controller="javaScriptController">
    <h2>Click below to get User Name:</h2>
    <div>
        <button onclick="javaScriptCall('Java Honk')">Get User name from JavaScript call to AngularJS</button>
        <div>User Name: {{usersName}}</div>
    </div>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

may be you can use, $scope.$apply() - it will works.

$scope.javaScriptCallAngular = function(value) {                
  $scope.usersName = value;
  $scope.$apply();
};
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda