anglejを使用し、DOMステートメントを使用していないjsファイルの文字列にテキストボックス(id = "lunch-menu"私はそれをしようとしたが、何も働かなかった。私はangularjsを初めて使っています。どうすればいいのか教えてください。anglejsを使用してjavascriptファイルの文字列にテキストボックス値を取得する方法
これは、あなたの入力に双方向結合(ng-model
)を定義している私のjsファイルとhtmlファイル
(function() {
\t // body...
\t 'use strict';
\t angular.module('LunchCheck', [])
\t .controller('LunchCheckController', LunchCheckController);
\t LunchCheckController.$inject=['$scope'];
\t function LunchCheckController($scope) {
\t //code to get the textbox user input value into a string
\t }
})();
<!DOCTYPE html>
<html>
<head>
<title>Lunch Checker</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="LunchCheckApp.js"></script>
</head>
<body ng-app="LunchCheck">
<div class="conatainer" ng-controller="LunchCheckController">
\t <h1>Lunch Checker</h1>
\t <div class="form-group form-control">
<input id="lunch-menu" type="text" placeholder="list comma separated dishes you usually have for lunch" ng-model="userInput">
</div>
<div class="form-group">
\t <button class="btn btn-default">Check If Too Much</button>
</div>
<div class="form-group message"></div>
</div>
</body>
</html>
あなたのコントローラ – Edison