I am developing an online course application and I am trying to display the course details of a course along with video lectures which are on youtube. My angular controller is fetching the course details from the node.js controller and displaying it on the html view, however it doesn't show get the youtube video link. Its because I changed the mongoose schema for storing course video from a String to String Array. If I keep the mongoose schema for course video as String, then I can view the video.
Here is the mongoose schema, file name is course.server.model.js
'use strict';
/**
* Module dependencies
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
/**
* Course Schema
*/
var CourseSchema = new Schema({
created: {
type: Date,
default: Date.now
},
title: {
type: String,
default: '',
trim: true,
required: 'Title cannot be blank'
},
content: {
type: String,
default: '',
trim: true
},
courseLecture: [{
week_number: { type: Number },
lecture_video: [String]
}],
user: {
type: Schema.ObjectId,
ref: 'User'
}
});
mongoose.model('Course', CourseSchema);
In the schema, I have kept lecture_video as String array within courseLecture.
Here is my angular controller. controller name is courses.client.controller.js
(function () {
'use strict';
angular
.module('courses')
.config(function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
'self',
'https://www.youtube.com/**'
]);
})
.controller('CoursesController', CoursesController);
CoursesController.$inject = ['$scope', 'courseResolve', 'Authentication'];
function CoursesController($scope, course, Authentication) {
var vm = this;
vm.course = course;
vm.authentication = Authentication;
$scope.product = {
name: 'some name',
description: 'some description',
media: [{
src: vm.course.courseLecture.lecture_video
}]
};
console.log('value of courseLecture: ' + vm.course);
console.log('value of youtube embed lecture is: ' + vm.course.courseLecture.lecture_video);
$scope.getIframeSrc = function(src) {
return 'https://www.youtube.com/embed/' + src;
};
}
}());
If I do console.log for vm.course.courseLecture.lecture_video then I get undefined. However, I do get undefined for it, even from node.js controller as well.
Here is my html view. file name :- view-course.client.view.html
<style>
.video-container {
height: 400px;
width: 200px;
}
.thumbnail1 {
height: 450px;
width: 220px;
}
</style>
<section>
<div class="page-header">
<h1 ng-bind="vm.course.title"></h1>
</div>
<small>
<em class="text-muted">
Posted on
<span ng-bind="vm.course.created | date:'mediumDate'"></span>
by
<span ng-if="vm.course.user" ng-bind="vm.course.user.displayName"></span>
<span ng-if="!vm.course.user">Deleted User</span>
</em>
</small>
<p class="lead" ng-bind="vm.course.content"></p>
<div ng-repeat="media in product.media">
<div class="thumbnail1" class="col-xs-12 col-sm-9">
<div class="video-container">
<iframe ng-src="{{getIframeSrc(media.src)}}" frameborder="5" allowfullscreen></iframe>
</div>
</div>
</div>
</section>
Right now with this, I can see the course details using REST calls, only the video link doesn't work, which starts working if in the course schema, in the courseLecture property, if I change the lecture_video from lecture_video: [String] to lecture_video: {type:String}. I can view the video. I want to store all the video links for a week in an array so the all the videos can be displayed. Please help me with what I am doing wrong here.