angularJs を使用したフォームがあります。すべてのコードは、質問の最後にあるプランカーで利用できます。
私のコントローラーの中に私が持っている
$scope.showTelfield= false; $scope.showEmailfield= false;
私のフォームと電話フィールドと電子メールフィールドで使用しています:
ng-show="showTelField" ng-show="showEmailField"
コントローラー内で設計されているため、ユーザーが選択オプションから選択した場合、これらの値は true である必要があります。
htmlで
<select class="form-control c-select" name="select" ng-model="feedback.myChannel" ng-options="channel.value as channel.label for channel in channels">
<option value="">Select a method</option>
</select>
コントローラーで:
$scope.feedback = {
myChannel: "",
firstName: '',
lastName: '',
agree: false,
email: ''
};
$scope.channels = [{
value: "Tel",
label: "Tel"
}, {
value: "Email",
label: "Email"
}, {
value: "Tel & Email",
label: "Tel & Email"
}];
//Telling browser to view telephone or Email feild if needed..
if($scope.feedback.myChannel === "Tel" || $scope.feedback.myChannel === "Tel & Email"){
$scope.showTelField = true }
if($scope.feedback.myChannel === "Email" || $scope.feedback.myChannel === "Tel & Email"){
$scope.showEmailField = true }
$scope.feedback.myChannel の値は、ユーザーの選択に基づいて空の文字列から "Tel"、"Email"、または "Tel & Email" に変更され、開発目的でのみ追加の div 内に表示されます。それらはユーザーの選択によって変わります。
$scope.feedback.myChannel の値は、私が開発のために作成している表示 div に従って変化しますが、すべての if ステートメントは機能しません。それはなぜですか?
あなたは私のプランカーで私のコードを見ることができます ここに私のプランカーがあります