如何显示范围属性在文本输入angularJS

问题描述 投票:1回答:1

我在AngularJS新的,不能做简单的任务。我希望你能帮助我。我的目标是从显示控制器中的$ scope属性“服务器”时,它加载到文字输入的观点:

我的控制器:

(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”;是全球性的。

我想,在视图中的文字输入显示加载。

我的观点是

<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>

我用NG-模型来我的属性绑定到的TextInput,但不知道为什么它不工作。我想这是简单的任务。谢谢。

angularjs angularjs-scope
1个回答
1
投票

为什么要混淆两者$范围和VM?上HTML使用VM和控制器作为语法如下,

 vm.server = SERVER_HOST_NAME;

与HTML会,

<input ng-model="vm.server" type="text" />
© www.soinside.com 2019 - 2024. All rights reserved.