Angularjs ng显示ng隐藏有角度的问题回答
我有一个网站,在那里我显示不同的问题,当你点击其中一个出现答案,如果你再次点击,就会消失。我试着在家里做这件事 但目前我无法做到Angularjs ng显示ng隐藏有角度的问题回答,angularjs,Angularjs,我有一个网站,在那里我显示不同的问题,当你点击其中一个出现答案,如果你再次点击,就会消失。我试着在家里做这件事 但目前我无法做到 <ul id="question-list"> <li> <h1><a ng-click="answer = !answer" >What is this?</a></h1> <h3 ng-show="answer"> t
<ul id="question-list">
<li>
<h1><a ng-click="answer = !answer" >What is this?</a></h1>
<h3 ng-show="answer"> this</h3>
</li>
<li>
<h1 >What is the question?</h1>
<h3>It </h3>
</li>
<li>
<h1>What is the question?</h1>
<h3> Ipsum.</h3>
</li>
您发布的代码在正确设置的应用程序中运行良好,所以我猜这就是问题所在
<div ng-app="app" ng-controller="ctrl">
<ul id="question-list">
<li>
<h1><a ng-click="answer = !answer">What is this?</a></h1>
<h3 ng-show="answer"> this</h3>
</li>
<li>
<h1>What is the question?</h1>
<h3>It </h3>
</li>
<li>
<h1>What is the question?</h1>
<h3> Ipsum.</h3>
</li>
</ul>
</div>
<script>
var app = angular.module('app',[]);
app.controller('ctrl', function ($scope) {
$scope.answer = true;
});
</script>
-
这是什么?
这
-
问题是什么?
信息技术
-
问题是什么?
乱数假文。
var-app=angular.module('app',[]);
应用程序控制器('ctrl',函数($scope){
$scope.answer=true;
});
您发布的代码在正确设置的应用程序中运行良好,所以我猜这就是问题所在
<div ng-app="app" ng-controller="ctrl">
<ul id="question-list">
<li>
<h1><a ng-click="answer = !answer">What is this?</a></h1>
<h3 ng-show="answer"> this</h3>
</li>
<li>
<h1>What is the question?</h1>
<h3>It </h3>
</li>
<li>
<h1>What is the question?</h1>
<h3> Ipsum.</h3>
</li>
</ul>
</div>
<script>
var app = angular.module('app',[]);
app.controller('ctrl', function ($scope) {
$scope.answer = true;
});
</script>
-
这是什么?
这
-
问题是什么?
信息技术
-
问题是什么?
乱数假文。
var-app=angular.module('app',[]);
应用程序控制器('ctrl',函数($scope){
$scope.answer=true;
});
您可以在模板中完成这一切,例如:
<p ng-click="x=!x">Something<span ng-show="x"> else</span>.</p>
还有别的东西
单击
将使
显示并消失。您可以在模板中完成所有操作,例如:
<p ng-click="x=!x">Something<span ng-show="x"> else</span>.</p>
还有别的东西
单击
将使
显示并消失。每个问题都有自己的答案,以便显示随附的答案
HTML:
每个问题都有自己的答案,以便显示随附的答案 HTML:
-
这是什么?
这
,-
问题是什么?
信息技术
-
问题是什么?
乱数假文。
var-app=angular.module('app',[]);
应用程序控制器('控制'),功能($范围){
$scope.answer=true;
});
-
这是什么?
这
,-
问题是什么?
信息技术
-
问题是什么?
乱数假文。
var-app=angular.module('app',[]);
应用程序控制器('控制'),功能($范围){
$scope.answer=true;
});
角度代码是什么样子?$scope.answer=true;你能把所有的密码都贴出来吗。到目前为止,您发布的所有内容都是正确的。您的代码有什么问题,您的逻辑不起作用,我已在本地进行了检查。您的角度代码是什么样子的?$scope.answer=true;你能把所有的密码都贴出来吗。到目前为止,您发布的所有内容都是正确的。您的代码有什么问题,是您的逻辑不起作用,我已在本地进行了检查,它可以按照您的预期工作。如果您希望默认显示文本,那么您必须使用ng init
,或者使用ng hide
而不是ng show
(但同意,ng init
会更干净)。如果您希望默认显示文本,则必须同时使用ng init
,或者使用ng hide
而不是ng show
(但同意,ng init
会更干净)。
var app = angular.module("myApp",[]);
app.controller("MyCtrl", ["$scope", function ($scope) {
var vm = this;
vm.questionList = [{
"question" : "What is this question 1?",
"answer" : "this is answer1"
},{
"question" : "What is this question 2?",
"answer" : "this is answer2"
}];
}]);
<div ng-app="app" ng-controller="control">
<ul id="question-list">
<li>
<h1><a ng-click="answer = !answer">What is this?</a></h1>
<h3 ng-show="answer"> this</h3>
</li>
,<li>
<h1 ng-click="answer = !answer">What is the question?</h1>
<h3 ng-show="answer">It </h3>
</li>
<li>
<h1 ng-click="answer = !answer">What is the question?</h1>
<h3 ng-show="answer"> Ipsum.</h3>
</li>
</ul>
</div>
<script>
var app = angular.module('app',[]);
app.controller('control', function ($scope) {
$scope.answer = true;
});
</script>