Javascript 从视图修改ng模型

Javascript 从视图修改ng模型,javascript,angularjs,Javascript,Angularjs,我是AngularJS的新手,如何从我的角度更新ng模型的价值? 现在我有表单,我正在更新app_键输入,但是当我调用我的模块并检查$scope.variable时,值没有改变 这是我的密码 <div> <br> <div class="field_row"> <label for="app_key">AppKey:</label> <input id="app_key" typ

我是AngularJS的新手,如何从我的角度更新ng模型的价值? 现在我有表单,我正在更新app_键输入,但是当我调用我的模块并检查$scope.variable时,值没有改变

这是我的密码

  <div>
    <br>
    <div class="field_row">
        <label for="app_key">AppKey:</label>
        <input id="app_key" type="text" ng-model="appKey"> --> this is the input that I´m changing the value
    </div>
</div>

<div class="modal-footer">
   <button type="button" class="btn btn-info" ng-click="selectUser()">
    Select
   </button>
</div>
解决方案

我不知道为什么,但为了让它工作,我需要将ng模型传递给控制器函数

  <input id="app_key" type="text" ng-model="appKey" ng-change="changeAppKey(appKey)">

我是用你的代码做的。它似乎工作得很好。您确定您的
setAppKey
功能正确吗

JS

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
    $scope.selectUser = function () {
        console.log($scope.appKey);
    };
}
HTML

<div ng-controller="MyCtrl">
    <div>
        <div class="field_row">
            <label for="app_key">AppKey:</label>
            <input id="app_key" type="text" ng-model="appKey">
        </div>
    </div>
    {{appKey}}
    <div class="modal-footer">
        <button type="button" class="btn btn-info" ng-click="selectUser()">
        Select
        </button>
    </div>
</div>

AppKey:
{{appKey}}
挑选
我是用你的代码做的。它似乎工作得很好。您确定您的
setAppKey
功能正确吗

JS

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
    $scope.selectUser = function () {
        console.log($scope.appKey);
    };
}
HTML

<div ng-controller="MyCtrl">
    <div>
        <div class="field_row">
            <label for="app_key">AppKey:</label>
            <input id="app_key" type="text" ng-model="appKey">
        </div>
    </div>
    {{appKey}}
    <div class="modal-footer">
        <button type="button" class="btn btn-info" ng-click="selectUser()">
        Select
        </button>
    </div>
</div>

AppKey:
{{appKey}}
挑选

您在
html
中定义控制器的位置?是的,它以前在HTMLD上定义过。您在浏览器控制台上是否有任何错误?不,根本没有错误,我可以看到$scope.appKey只是没有使用添加到中的新值进行更新input@paul这是你想做的吗?你在
html
中定义你的控制器的地方?是的,它以前在HTMLD上定义过。你在浏览器控制台上有没有错误?没有,根本没有错误,我可以看到$scope.appKey只是没有使用添加到中的新值进行更新input@paul这是你想做的吗?它确实有效,我不知道为什么不在我的应用程序上。但是非常感谢!,我将使用此代码作为基础来比较它的工作情况。的确,我不知道为什么不在我的应用程序上。但是非常感谢!,我将使用此代码作为比较的基础