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

  • SEARCH
  • Home
  • 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 8506919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:43:27+00:00 2026-06-11T02:43:27+00:00

I am just starting with AngularJS and am trying to figure out how to

  • 0

I am just starting with AngularJS and am trying to figure out how to easily reference (bind?) scope variables from outside the Angular controller.

Simple code:

<div ng-controller="Ctrl">
  <label>Name:</label>
  <input type="text" ng-model="yourNameInput" placeholder="Enter a name here">
  <input type="button" onClick="console.log(inputName);">
  <hr>
  <h1 ng-bind-template="Hello, {{yourNameInput}}"></h1>
</div>

How would I bind {{yourNameInput}} to inputName var that will be available to the rest of my application? There’s one ugly way I managed to do that:

$scope.change = function() { inputName = $scope.yourNameInput; }

and then:

<... ng-change = "change()">

Anything more elegant?

  • 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-11T02:43:28+00:00Added an answer on June 11, 2026 at 2:43 am

    You can inject $window into your controller and make it available on the scope. See example.

    function Ctrl($scope, $window) {
        $scope.window = $window;
    }​
    

    …

    <input type="text" ng-model="yourNameInput" placeholder="Enter a name here" ng-change="window.yourName = yourNameInput">
    

    For broader use you can make it available on the $rootScope. See another example.

    angular.module('myApp', [])
        .run(function($rootScope, $window){
            $rootScope.window = $window;
        });
    

    Also you can see Call Angular JS from legacy code.

    For console.log() you can use

    <input type="button" onClick="console.log('{{yourNameInput}}');" value="Log">
    

    See example.

    If you want to debug AngularJS application you can use AngularJS Batarang (textual description and source code)

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

Sidebar

Related Questions

Just starting to figure Python out. I've read this question and its responses: Is
Just starting out using MVC3 and hit a problem trying to build a drop-down
Just starting to play around with bootstrap and it's amazing. I'm trying to figure
Hey - just starting out trying to get some openGL into my iphone app
Just starting out with OOP in PHP and in general. From what I have
I just starting out trying to write a federated claims provider I'm using the
Just starting to learn scala.. I can't seem to figure out how to compile
Just starting out using model view controller design pattern in a mobile application and
Just starting out in python on a pendrive 12.04 Kubuntu environment. I had to
Just starting out with subversion, have set up repos for 3 current projects and

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.