簡體   English   中英

單擊按鈕,AngularJS將值設置為文本框

[英]Angularjs set value to text box on click of button

我的angularjs項目中有以下UI 在此處輸入圖片說明

在單擊文本框前面的按鈕時,我正在調用一個其代碼為

$scope.generateAppId = function(){
    var reqData = {};
    var res = $http.post('http://192.168.1.30:8090/apps/createappid', $scope.reqData);
    res.success(function(data, status, headers, config) {
        $scope.message = data;
        $scope.appId = data.appId
        console.log(data);
    });
} 

這是成功調用API時的響應數據

{
id: null
name: null
appId: "c5b09133-eb40-4b90-b6de-5cfd054b2de9"
secret: null
domain: null
}

現在,我想在JSON響應中為文本框設置值appId

您不能為文本框使用單獨的$ scope變量,並將該變量作為文本框中的模型嗎?

您可以在不需要顯示任何內容時將變量設置為空字符串,然后將變量設置為$ scope.appId

$scope.textbox = ''

<input type='textbox' ng-model='textbox' name='textbox'>

然后

$scope.textbox = $scope.appId

請閱讀以下教程: https : //docs.angularjs.org/api/ng/directive/ngValue

將控制器綁定到您的html並執行以下操作:

<input type="text" ng-value="appId">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM