1

I'm new in AngularJS, and can't do the simple task. I hope that you will help me. My goal is to display the $scope property "server" from controller to text input in the view when it's loaded:

My controller:

(function () {

  'use strict';

  angular
    .module('app')
    .controller('HomeController', homeController);

  homeController.$inject = ['authService', 'httpService'];

  function homeController(authService, $scope) {

    var vm = this;
    vm.auth = authService;
    $scope.server = SERVER_HOST_NAME;
    console.log ($scope.server);
  }
})();

var SERVER_HOST_NAME = "anysite.com"; is global.

And I want, that the text input in the view is display that for loading.

My view is

<h4 ng-if="vm.auth.isAuthenticated()">
    You are logged in!
</h4>
<h4 ng-if="!vm.auth.isAuthenticated()">
  You are not logged in! Please <a ng-click="vm.auth.login()">Log In</a> to continue.
</h4>

<div class="container">
  <label>Team city server:</label>

  <input ng-model="server" type="text" />
    <button ng-click="getBuilds()">Extract</button>
</div>

I use ng-model to bind my property to textinput, but have no idea why it is not working. I guess this is simple task. Thank you.

1 Answer 1

1

why you are mixing up both $scope and vm ? use vm and controller as syntax on HTML as follows,

 vm.server = SERVER_HOST_NAME;

and the HTML would be,

<input ng-model="vm.server" type="text" />
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for you reply, I did what you say, but the problem is still apper. The textinput didn't display the vm.server property
can you console.log and see what is the value of vm.server inside the controller
I can't undestand, but you solution is worked, I don't know why I can't get this result at the first time, but now is displaying, many thanks to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.