クリックすると追加ボタンの上に追加の入力テキストフィールドが表示されます。 しかし、それは動作せず、コンソールに参照エラーが表示されています。Plnkrコントローラが動作しない
新鮮な角度で始めるので、私は少し初心者です。どんな助けも素晴らしいだろう。 ありがとう!
http://plnkr.co/edit/EFF63kpjiSg3EPQa7tkz?p=preview
HTML
<!DOCTYPE html>
<html ng-app="testViewer">
<head>
<script data-require="[email protected]*" data-semver="2.0.0" src="https://code.angularjs.org/2.0.0-snapshot/angular2.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body ng-controller="MainController">
<label for="question">
Question:
<input type="text" class="form-control" placeholder="Type Question Here" />
</label>
<br />
<label for="answers">
Correct Answers (optional):
<br />
<button type="button" class="btn btn-success btn-default" ng-click="shortAnswer()">Add</button>
<button type="button" class="btn btn-danger btn-default" ng-click="shortAnswer()">Delete</button>
</label>
<br />
<br />
<label for="explanation">
Explanation:
<input type="text" class="form-control" placeholder="Type Explanation Here" />
</label>
</body>
</html>
JS
// Code goes here
var app = angular.module("testViewer");
var MainController = function($scope) {
scope.shortAnswer = function() {
$('.add').click(function() {
var label = 1;
$(".content2").append('<label for="' + label + '"><input type="text" class="form-control" placeholder=""></label>');
label++;
});
$(".content2").on("click", ".remove", function() {
$(this).parent().remove();
});
};
};
app.controller("MainController", MainController);
私は間違った落下にリンクしました!しかし、そのソリューションは、私がそのソリューションにリンクさせようとしていたものでは機能しませんでした。何か案は? – RyeGuy
@RyeGuyおっと、よろしくお願いします – Deep
@RyeGuyもう一度plunkerの答えを更新しました。 – Deep