如何推入服务内部的数组并推入对象的对象 [英] how to push in array which is inside of services and push in object of an object
问题描述
我有这个HTML
< ul >
< li data-ng-repeat = q在QuizObj >
< fieldset > < ; 图例 > 所有参数< / legend >
< h1 > { {q.Quiz}} < / h1 >
< h3 > ; 选项< / h3 >
< h3 > ; 回答< / h3 >
< 输入 类型 = radio / > {{q.options [1]}}
< 输入 type = < span class =code-keyword> radio / > {{q.options [2]}}
< 输入 类型 = radio / > {{q.options [3]}}
< 输入 type = radio / > {{q.options [4]}}
< h4 > 答案< / h4 >
< 输入 type = radio / > {{q.answer}}
< / fieldset >
< / li >
< / ul >
< input 类型 = text ng-model = ans >
< 输入 type = < span class =code-keyword> text ng-model = 问题 >
< 输入 type = text ng-model = 类型 >
< 输入 type = 按钮 data-ng-click = addQuiz() < span class =code-keyword>>
这是js角码
angular.module(' quizApp',[])
。 controller(' mainCtrl', function ( $ scope,crudService){
$ scope.name = this ;
alert( JSON .stringify(crudService.quiz));
$ scope.QuizObj = crudService.quiz;
})
.service(' crudService', function (){
this .quiz = [
{
Quiz: 什么是C#,
选项:{ 1 :' P-lang',
2 :' h-lang',
3 :' A-lang',
4 :' nothing'
},
类型:' radio',
回答: 1
},
{
测验: 什么是J#,
选项:{ 1 :' P-lang' ,
2 :' h-lang',
3 :' A-lang',
4 :' nothing'
},
类型:' radio',
回答: 1
},
{
测验: 什么是VB ,
选项:{ 1 :' PL',
2 :' hL',
3 :' AL',
4 :' < span class =code-string> nothing'
},
类型:' 收音机',
回答: 1
}
]
})
i有一些问题
i想要在测验中添加问题而测验对象在服务中如何添加这个我在做什么
这个
$ scope.addQuiz = function ($ scope){
crudService.quiz.push({
测验:$ scope.Question,
类型:$ scope.type,
回答:$ scope.ans
})
}
但显示错误
TypeError:无法读取属性'问题'未定义
如何推送服务的对象(测验)。 ??
如何推入选项,这是Quiz对象中的另一个对象。 ??
加上我想让用户添加答案类型
类型是
1:true \ false(复选框)
2:Mulitiple回答(复选框)
3.单一回答(收音机)
怎么办?虽然我在测验中添加了一个选项,但不知道怎么做并创建它的布局??
scope,crudService){
scope.name = this;
alert( JSON .stringify(crudService.quiz));
scope.QuizObj = crudService.quiz;
})
.service(' crudService', function (){
this .quiz = [
{
Quiz: 什么是C#,
选项:{ 1 :' P-lang',
2 :' h-lang',
3 :' A-lang',
4 :' nothing'
},
类型:' radio',
回答: 1
},
{
测验: 什么是J#,
选项:{ 1 :' P-lang' ,
2 :' h-lang',
3 :' A-lang',
4 :' nothing'
},
类型:' radio',
回答: 1
},
{
测验: 什么是VB ,
选项:{ 1 :' PL',
2 :' hL',
3 :' AL',
4 :' < span class =code-string> nothing'
},
类型:' 收音机',
回答: 1
}
]
})
i有一些问题
i想要在测验中添加问题而测验对象在服务中如何添加这个我在做什么
这个
i have this html
<ul>
<li data-ng-repeat="q in QuizObj">
<fieldset><legend>All Quizes </legend>
<h1>{{q.Quiz }}</h1>
<h3>options</h3>
<h3>answer</h3>
<input type="radio" />{{q.options[1]}}
<input type="radio" />{{q.options[2]}}
<input type="radio" />{{q.options[3]}}
<input type="radio" />{{q.options[4]}}
<h4>Answer</h4>
<input type="radio" />{{q.answer}}
</fieldset>
</li>
</ul>
<input type="text" ng-model="ans">
<input type="text" ng-model="Question" >
<input type="text" ng-model="type">
<input type="button" data-ng-click="addQuiz()">
and this is js angular code
angular.module('quizApp',[])
.controller('mainCtrl',function($scope,crudService){
$scope.name="this";
alert(JSON.stringify(crudService.quiz));
$scope.QuizObj= crudService.quiz;
})
.service('crudService',function(){
this.quiz=[
{
Quiz: "what is the C#",
options: { 1: 'P-lang',
2:'h-lang',
3: 'A-lang',
4: 'nothing'
},
type: 'radio',
answer: 1
},
{
Quiz: "what is the J#",
options: { 1: 'P-lang',
2:'h-lang',
3: 'A-lang',
4: 'nothing'
},
type: 'radio',
answer: 1
},
{
Quiz: "what is the VB",
options: { 1: 'PL',
2:'hL',
3: 'AL',
4: 'nothing'
},
type: 'radio',
answer: 1
}
]
})
i have a some problem
i want to add question into quiz while quiz object is in service how to add this i am doing
this
$scope.addQuiz= function($scope){
crudService.quiz.push({
Quiz: $scope.Question,
type: $scope.type,
answer: $scope.ans
})
}
but showing me an error
TypeError: Cannot read property 'Question' of undefined
how to push in services's object (quiz). ??
how to push in option which is another object in Quiz object. ??
plus i want to allow user to add type of answer
types are
1: true\false (checkbox)
2: Mulitiple answer (checkbox)
3. single answer (radio)
how to do this ?? although i have added a opition in quiz but don't know how to do this and create its layout??
scope,crudService){
scope.name="this"; alert(JSON.stringify(crudService.quiz));
scope.QuizObj= crudService.quiz; }) .service('crudService',function(){ this.quiz=[ { Quiz: "what is the C#", options: { 1: 'P-lang', 2:'h-lang', 3: 'A-lang', 4: 'nothing' }, type: 'radio', answer: 1 }, { Quiz: "what is the J#", options: { 1: 'P-lang', 2:'h-lang', 3: 'A-lang', 4: 'nothing' }, type: 'radio', answer: 1 }, { Quiz: "what is the VB", options: { 1: 'PL', 2:'hL', 3: 'AL', 4: 'nothing' }, type: 'radio', answer: 1 } ] })
i have a some problem
i want to add question into quiz while quiz object is in service how to add this i am doing
this
这篇关于如何推入服务内部的数组并推入对象的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!