如何将更多学生记录添加到角度数组中,例如:firstName,last Name,费用($ scope.student)?
这就是我所拥有的:
var mainApp = angular.module("mainApp", []);
mainApp.controller('studentController', function($scope) {
$scope.student = {
firstName: "Muhammad",
lastName: "Waqas",
fees:500,
subjects:[
{name:'Physics',marks:70},
{name:'Chemistry',marks:80},
{name:'Math',marks:65}
],
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName + " " + studentObject.lastName;
}
};
});
答案 0 :(得分:0)
我在这里不清楚这个问题。但你打算做的是在students
中创建一个$scope
数组,你可以这样做。
mainApp.controller('studentController', function($scope) {
$scope.students = [];
$scope.students.push({
firstName: "Muhammad",
lastName: "Waqas",
fees:500,
subjects:[
{name:'Physics',marks:70},
{name:'Chemistry',marks:80},
{name:'Math',marks:65}
],
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName + " " + studentObject.lastName;
}
});
//add more students using .push()
});
你的学生阵列在$ scope中。
答案 1 :(得分:0)
您不能在$scope.student
上执行此操作,而只是创建student
作为对象并创建数组$scope.students
并将每个student
对象存储在该数组中。您可以创建var student1,var student2
存储有关其他学生的信息
mainApp.controller('studentController', function ($scope) {
$scope.students = [];
$scope.studentFullName = function () {
};
var student = {
firstName: "Muhammad",
lastName: "Waqas",
fees: 500,
subjects: [
{name: 'Physics', marks: 70},
{name: 'Chemistry', marks: 80},
{name: 'Math', marks: 65}
],
fullName: this.firstName + ' ' + this.lastName
};
$scope.students.push(student);
});