Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9267647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:36:04+00:00 2026-06-18T14:36:04+00:00

I’ve a question about Angularjs data binding feature. If i write: <div>Hello {{name}}!</div> and

  • 0

I’ve a question about Angularjs data binding feature.

If i write:

<div>Hello {{name}}!</div>

and i’ve in the controller.js something like:

$scope.name = 'Bruno';

The result will be “Hello Bruno!”… and this is wonderful! Now i edited the template:

<div>Hello <span id="name"></span>!</div>

and i also added this javascript function just before close the body:

<script src="lib/angular/angular.js"></script>
<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/directives.js"></script>

<script type="text/javascript">

  function fillName(subject) {
    $("#name").text("Hello " + subject);
  }

  fillName({{name}}); // this throws "SyntaxError: invalid property id"

</script>
</body>

So my question is:

Is it possible in AngularJS to use data bindings inside a classic javascript function?


UPDATE:

// i changed: fillName({{name}}); with:
fillName('{{name}}');

and this solved the error… but still the name doesn’t appear… i’m still working on this…

suggestions always welcome!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:36:06+00:00Added an answer on June 18, 2026 at 2:36 pm

    [Update] Well, it appears that I misunderstood your question, as you seem to have solved your issue, but perhaps other people will stumble upon this information based on the title of the question.


    I will prefix my answer with the following caveat: if you’re writing an AngularJS application, you’ll want to use the features Angular provides, like directives, for doing this kind of stuff, rather than going outside the Angular application lifecycle and writing global functions, etc. In the interest of the academic answer to the question, however, here it is.

    Overview

    The Angluar magic that you’re trying to get access to here is based on a few facilities:

    Scope (docs)

    Scopes provide a context for Angular expressions (the things you put in attributes and the double curlies) and provide the functions necessary to watch for changes in the evaluation of these expressions in that context. For example, Scope#$watch allows you to register a callback that is executed whenever the evaluation of an expression changes.

    $interpolate (docs)

    Interpolate takes a string that can include expressions inside double curlies and turns it into a new string with the expression results interpolated into the original string. (Calling $interpolate(str) returns a function which, when called against an object that provides scope, returns a string.)

    Putting it Together

    When writing an Angular app, you often don’t have to worry about these details–your controllers automatically get passed a scope, and your DOM text is automatically interpolated. Since you’re trying to access these things outside of the lifecycle of an Angular app, you’ll have to jump through some of these previously hidden hoops.

    angular.injector (docs)

    When you register services, filters, directives, etc. on a module using app.controller, app.factory, and so forth, the functions you provide are invoked by the injector. Angular creates one for you in an Angular app, but since we’re not using one, you’ll need to use angular.injector to create one yourself.

    Once you have an injector, you can use injector.invoke(fn) to execute the function fn and inject any dependencies (like $interpolate) for use inside the function.

    A simple example

    Here’s a very basic example that

    • Provides two-way data binding between an input and a variable
    • Provides data binding into an HTML view using $interpolate
    Name: <input id="name" type="text" autocomplete="off">
    <button id="setname">Set name to Bob</button>
    <div id="greeting"></div>
    
    var injector = angular.injector(['ng']);
    
    injector.invoke(function($rootScope, $interpolate) {
      var scope = $rootScope.$new();
      var makeGreeting = $interpolate("Hello {{name}}!");
    
      scope.$watch('name', function() {
        var str = makeGreeting(scope);
        $("#greeting").text(str);
        $("#name").val(scope.name);
      });
    
      var handleInputChange = function() {
        scope.$apply(function() {
          scope.name = $('#name').val();
        });
      };
    
      var setNameToBob = function() {
        scope.$apply(function() {
          scope.name = "Bob";
        });
      };
    
      $("#name").on('keyup', handleInputChange);
      $("#setname").on('click', setNameToBob);
      handleInputChange();
    });
    

    Here is a jsFiddle that demonstrates the technique: http://jsfiddle.net/BinaryMuse/fTZu6/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't have much knowledge about the IPv6 protocol, so sorry if the question
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.