Videogular - how to play given video file on div ng-click? - angularjs

I have a list of items and and would like to after the ng-click on selected item play videofile with given URL.
It means that player instance for view should be hidden and after the click on the list item should be played given video file in fullscreen, loop and without sounds.
How can i do it please?
I tried to to do via API.play() method from:
http://www.videogular.com/tutorials/videogular-api/
But without the luck.
Many thanks for any advice.

You can use API.toggleFullScreen() method.
HTML
<div ng-controller="HomeCtrl as controller" class="videogular-container">
<videogular vg-player-ready="controller.onPlayerReady($API)" vg-theme="controller.config.theme.url">
<vg-media vg-src="controller.config.sources"
vg-native-controls="true">
</vg-media>
</videogular>
<div ng-click="controller.API.toggleFullScreen()">open in fullscreen</div>
</div>
JS
'use strict';
angular.module('myApp',
[
"ngSanitize",
"com.2fdevs.videogular"
]
)
.controller('HomeCtrl',
function ($sce) {
this.onPlayerReady = function onPlayerReady(API) {
this.API = API;
};
this.config = {
preload: "none",
sources: [
{src: $sce.trustAsResourceUrl("http://static.videogular.com/assets/videos/videogular.mp4"), type: "video/mp4"},
{src: $sce.trustAsResourceUrl("http://static.videogular.com/assets/videos/videogular.webm"), type: "video/webm"},
{src: $sce.trustAsResourceUrl("http://static.videogular.com/assets/videos/videogular.ogg"), type: "video/ogg"}
],
theme: {
url: "http://www.videogular.com/styles/themes/default/latest/videogular.css"
}
};
}
);

Related

Pie Chart using Chartjs in angularjs 1.5.8 with components not showing up in view

I want to create a dashboard like feature on my existing angular app using Chart.js. So, I created a view for the dashboard.
<md-content layout-padding layout-fill flex class="animated fadeIn">
<div layout-padding>
<md-card-title>
<md-card-title-text>
<span class="md-headline">Dashboard</span>
</md-card-title-text>
</md-card-title>
</div>
<md-divider></md-divider>
<div>
<md-grid-list md-cols-gt-md="12" md-cols-sm="3" md-cols-md="8"
md-row-height-gt-md="1:1" md-row-height="4:3"
md-gutter-gt-md="8px" md-gutter-gt-sm="4px" md-gutter="2px">
<md-grid-tile md-colspan-gt-sm="3" md-rowspan-gt-sm="3">
<pie-chart header="'Auths'" auth-counts="ctrl.authCounts" flex-gt-sm></pie-chart>
</md-grid-tile>
</md-grid-list>
</div>
</md-content>
The dashboard controller is loaded from the route (ui.router). The controller is empty at the moment.
//router
.state('home.dashboard', {
url: '/dashboard',
controller: 'DashboardController as ctrl',
templateUrl: baseUrl + 'Scripts/src/views/dashboard/dashboard.home.html'
})
function DashboardController() {
var ctrl = this;
ctrl.$onInit = function () {
console.log('testing');
ctrl.authCounts = [800, 200];
}
}
Then, the component pie-chart looks like the following.
(function () {
'use strict';
angular.module('chart')
.component('pieChart', {
controller: PieChartComponentController,
templateUrl: 'Scripts/src/views/dashboard/pie.chart.template.html',
bindings: {
header: '<',
authCounts: '<'
}
});
PieChartComponentController.$inject = ['$timeout'];
function PieChartComponentController($timeout) {
var $ctrl = this;
$ctrl.$onInit = function () {
var myPieChart;
var data;
}
$ctrl.isArrayEmpty = function (authCount) {
if (!authCount) return true;
return authCount.length === 0;
}
$ctrl.createChart = function () {
var pieData = {
labels: ["Purple","Green","Orange","Yellow"],
datasets: [
{
data: [20, 40, 10, 30],
backgroundColor: ["#878BB6","#4ACAB4","#FF8153","#FFEA88"]
}
]
};
var ctx = document.getElementById("myPieChart").getContext("2d");
var myPieChart = new Chart(ctx, {
type: 'pie',
data: pieData
});
} // end createChart()
}
})();
And the pie-chart template looks like the following.
<div layout-align="start center" ng-if="$ctrl.isArrayEmpty($ctrl.authCounts)">
Not enough information available to create the chart.
</div>
<canvas id="myPieChart" width="250" height="250" ng-init="$ctrl.createChart()" ng-if="$ctrl.isArrayEmpty($ctrl.authCounts)" flex-gt-sm></canvas>
</md-card-content>
It seems like everything is fine, but the canvas height and width is 0 and the chart is not rendered.
However, if I remove the pie-chart component, and put the <canvas> element outside in the dashboard template and the data in the dashboard, it renders the chart. But that's not what I want to do, though. I need to have component for each type. So, what am I doing wrong that's causing this behavior?
I also tried angular-chart.js that showed the same behavior. If I put the <canvas> element in the dashboard template, it displays the chart but not from inside pie-chart element. I need help troubleshooting it. I'm definitely missing something here but can't figure out what. Is the canvas being rendered before the data is provided, or is there something going on that I'm overlooking (or oblivious about)?

default data not coming in dropdown using angular JS

I am trying to load data to select box in angular JS. Data are getting loaded but the default value is coming as empty as shown below. Can any one please help.
<option label="CURRENT" value="object:4">CURRENT</option><option label="description of Version 2" value="object:5">description of Version 2</option><option label="description of Version 3" value="object:6">description of Version 3</option><option label="description of Version 4" value="object:7">description of Version 4</option></select>
Please find my code below :
app.jsp
<!DOCTYPE html>
<html lang="en">
<body class="internal" >
<div id="contentContainer" class="stratum" data-ng-controller="appController">
<div id="businessDropDownDiv" class="column column.one-quarter-">
<div class="selectLabel">
<label for="businessSelect">Business Area</label>
</div>
<div>
<!-- <select ng-init="item.versionID=versions[0]" ng-model="item.versionID" ng-selected="0" ng-options="version.name for version in versions" required> -->
<select data-ng-init="business.data.businessId=business[0]" data-ng-model="business.data.businessId" data-ng-options="option.businessArea for option in business" class="filter">
</select>
</div>
</div>
</div>
</body>
<script type="text/javascript">
var contextPath = "<%= request.getContextPath() %>";
var appUrl = "<%= request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() %>";
var isSessionExpired = false;
</script>
<!-- JavaScripts Require JS Library and App JS Files -->
<script type="text/javascript" data-main="<%=request.getContextPath() %>/resources/js/app/uptimeReport.js" src="<%=request.getContextPath() %>/resources/js/libs/requirejs/require.js"></script>
</body>
</html>
uptimeReport.js
'use strict';
requirejs.config(
{
/** set up any additional paths that are outside of your application base * */
paths:
{
angular: contextPath + '/resources/js/libs/angularJS/angular',
jquery: contextPath + '/resources/js/libs/jquery/jquery',
uptimeReportBarChart : contextPath + '/resources/js/app/uptimeReportD3BarChart',
uptimeReportD3LineChart : contextPath + '/resources/js/app/uptimeReportD3LineChart',
d3Chart: contextPath + '/resources/js/libs/d3Charts/d3',
d3pkChart: contextPath + '/resources/js/libs/d3Charts/pk'
},
/**
* The following is not required in this example, but it is an example of
* how to make non-AMD java script compatible with require
*/
shim: {
angular: {
exports: 'angular'
},
d3Chart: ['jquery'],
d3pkChart: ['d3Chart']
},
deps: ['app']
});
app.js
'use strict';
require([
'angular'
], function (angular) {
require([
'controller/environmentController',
'uptimeReportBarChart',
'd3Chart', 'd3pkChart',
'uptimeReportD3LineChart'
], function (appCtrl) {
angular.
module('myApp',[]).
controller('appController', appCtrl);
angular.bootstrap(document, ['myApp']);
console.log("in App.js");
});
});
environmentController.js
'use strict';
define([
'angular'
], function (angular) {
return ['$scope', '$http',
function($scope, $http) {
console.log("in controller123.js");
var businessUrl="http://localhost:8080/UptimeReport/services/getBusinessAreas";
$http.get(businessUrl).then(function(response) {
$scope.business = [ {
"id": "0",
"businessArea": "CURRENT",
"businessId": "CURRENT"
},
{
"id": "114",
"businessArea": "description of Version 2",
"businessId": "version2"
},
{
"id": "126",
"businessArea": "description of Version 3",
"businessId": "version3"
},
{
"id": "149",
"businessArea": "description of Version 4",
"businessId": "version4"
}] ;
});
}];
});
I took a look at the code and made some corrections to make it work and understand your problem. Now coming to your problem solution. Add this line after retrieving the data using $http,get.
$scope.item={versionID:$scope.versions[0]};
For reference you can check the fiddle link where I have added the line and updated the code: https://jsfiddle.net/prijuly2000/43cs0y0c/
The problem with your current approach is that the model for select box is not initialized so it displays empty in the box as the dropdown will display the current value set to the model. So above line sets the initial value for the model which renders the first option selected in the view.
Let me know if this is not something that you didnt seek and I misunderstood the problem

Polymer 1.0: How can I add paper-card heading content dynamically

Is there a way I can create paper-card heading dynamically using some property inside custom element? Following is what I tried but didn't work. Probably this is not the way to achieve what I want:( I googled for a couple of hours but ended up with nothing!
Custom Element
<script>
(function () {
'use strict';
Polymer({
is: 'nearest-customers',
properties: {
customers: {
type: Array,
value: [],
notify: true
},
cardViewMaxRecords: {
type: Number,
notify: true
},
showFullCustomerList: {
type: Boolean,
value: false,
notify: true
},
headingContent: {
type: String,
value: 'Custom card heading'
}
},
ready: function () {
this.heading.textContent = this.headingContent
},
});
})();
</script>
HTML
<nearest-customers id="nearestCustomers" card-view-max-records="3"></nearest-customers>
...
...
...
<script type="text/javascript">
window.addEventListener('WebComponentsReady', function (e) {
var nearestCustomers = document.querySelector("#nearestCustomers");
nearestCustomers.headingContent= "<a href='someurl'><iron-icon icon='fa:arrow-left'></iron-icon></a> This is a new content";
}
</script>
My objective is to put an iron-icon before the heading text and the icon can be used as a link to somewhere.
Thanks in advance
I'm sure there's a better way, but I just added the styles and structure:
<div class="header paper-card">
<div class="title-text paper-card">
<iron-icon icon="book"></iron-icon> Reading List
</div>
</div>

Bind a controller $scope to objects in service

I'm creating a multi-step wizard using angularjs. The steps in the wizard could potentially change by actions the user takes. I'm storing the steps in a navigation service. I want the navigation controller to respond to changes in the navigation steps (which occurs in the service). How do I do this? The below code does not work. Also I am using ui-router for the wizard steps, I'm wondering if I'm going about this the wrong way and the steps should be stored in the parent $scope rather than in a service. But examples I've found online suggest using a service.
Here's a jsfiddle I wrote to exhibit the behavior (http://jsfiddle.net/uLytj/16/)
Wizard Navigation Service:
angular.module("myApp").factory("wizardNavigationSvc", [function () {
var service = {};
var steps = []
var currentStep = {};
var currentStepIndex = 0;
return {
init: function() {
steps = [{ state: "wizard.options", display: "Options", isActive: true, isFirstStep: true },
{ state: "wizard.newmodel", icon: "glyphicon-plus", otherActions: ["Add Another Model"] },
{ state: "wizard.other", display: "Other" },
{ state: "wizard.customer", display: "Customer Info" },
{ state: "wizard.shipping", display: "Shipping Info" },
{ state: "wizard.review", display: "Review", isLastStep: true }];
currentStep = steps[0];
currentStepIndex = 0;
},
steps: steps,
currentStep: currentStep
};
}])
Wizard Navigation Controller:
myApp.controller('wizardNavigationCtrl', ['wizardNavigationSvc', '$scope', '$state', function (wizardNavigationSvc, $scope, $state) {
wizardNavigationSvc.init();
$scope.steps = wizardNavigationSvc.steps;
$scope.currentStep = wizardNavigationSvc.currentStep;
}])
Wizard Navigation view:
<div>
<ul class="nav nav-tabs wizard-tabs">
<li ng-repeat="step in steps"
ng-class="step.isActive ? 'active': ''">
<a ui-sref="{{step.state}}">
<span ng-if="step.icon" class="glyphicon" ng-class="step.icon"></span>
<span ng-if="!step.icon">{{step.display}}</span></a>
</li>
</ul>
</div>
looking at your jsfiddle, its not defined because the service is not returning anything
Ex: on one of the lines (in your service) you have:
steps: steps,
currentStep: currentStep,
these should be:
steps: function(){return steps),
currentStep: function(){return currentStep},
I do not understand why this worked or was needed. I had to put my scope variables inside the service within another object. Here is the fiddle: http://jsfiddle.net/uLytj/25/
And here is the applicable code:
myApp.service("wizardNavigationSvc", [function () {
var navigation = {
steps: [],
currentStep: {},
currentStepIndex: 0
};

Create highcharts using angularjs ng-repeat

I have requested the json data containing all the information about people, and I want to a draw highcharts for each person based on the his information. I saw a solution here, but it seems that the config will always be overridden by the last li's config information. Is there a way to keep different configs for each highchart?
<div data-ng-repeat="a in people">
<h4>Method: {{ a.name }}</h4>
<highchart config="chartConfig"></highchart>
</div>
I encountered the same problem. It turns out that ng-repeat create new scope for each item, therefore the config attribute of highchart directive should correspond to the setting in ng-repeat. In your example, since you repeat the people by <div data-ng-repeat="a in people"> ,changing
<highchart config="chartConfig"></highchart>
to
<highchart config="a.chartConfig"></highchart>
should help.
I had create a plunker as an example.
You can use a partial view with a controller. Using ng-highcharts of course.
Like so, in your main you have:
<div data-ng-repeat="person in people">
<h4>Method: {{ person.name }}</h4>
<div data-ng-include="'/partial/chart.html'"></div>
</div>
Then in your partial, you have:
<div data-ng-controller="ChartController">
<highchart config="chartConfig"></highchart>
</div>
Then in your controller, you have:
app.controller('ChartController', function ($scope) {
$scope.chartConfig = {
chart: {
type: 'pie'
},
title: {
text: $scope.person.name
},
series: [{
data: $scope.person.chartdata
}]
};
});
Hope this helps.
You have to create a list then add to that list each chart configuration. Use ng-repeat in the list of charts:
//See: https://github.com/pablojim/highcharts-ng
var myapp = angular.module('myapp', ["highcharts-ng"]);
myapp.controller('myctrl', function ($scope) {
//The list who will contain each chart
$scope.chartlist = [];
//Chart 1
$scope.chartConfig = {
options: {
chart: {
type: 'bar'
}
},
series: [{
data: [10, 15]
}],
}
//Chart 2
$scope.chartConfig2 = {
options: {
chart: {
type: 'bar'
}
},
series: [{
data: [10, 15, 12, 8, 7]
}],
}
$scope.chartlist.push($scope.chartConfig);
$scope.chartlist.push($scope.chartConfig2);
});
then in your html use ng-repeat on the list of charts:
<div ng-app="myapp">
<div ng-controller="myctrl">
<div ng-repeat="char in chartlist" class="row">
<highchart id="chart1" config="char" class="span10"></highchart>
</div>
</div>
if you want to use dinamic data you can use a foreach to create each chart config, in this example I create a chart foreach object in the array 'a':
$scope.chartlist = [];
var a = [[1, 2],[2,4]];
function chardata(){
for (var i = 0; i < a.length; i++) {
$scope.chartConfig = {
options: {
chart: {
type: 'bar'
}
},
series: [{
data: a[i]
}],
}
$scope.chartlist.push($scope.chartConfig);
}
}
chardata();

Resources