How to display the content from controller on HTML page in angularjs? - angularjs

I am new to angularjs. I am trying to display the content from controller to the HTML but I am getting the data in console and I am not able to show it on the browser.
My html code:
<ion-list >
<ion-item ng-repeat="item in taskdetails" item="item" class="item-remove-animate item " class="itembg" on-swipe-right="showcard(item._id)" on-hold=" data.showReorder = !data.showReorder">
<span class="toptask" ng-hide="task.hide">
<span style="opacity:0.8"> {{ item.title| limitTo:10 }}<span ng-show="item.title.length> 10"><b> ...</b></span></span>
<small class="time " style="float:right;"> <i class="button button-icon icon ion-play balanced" ng-class="{ 'ion-pause assertive': !data.paused, 'ion-play balanced': data.paused}" ng-click="play5(item.id)" ></i>
</small>
<div style="float:right;margin-right:5px; font-size: 32px;
position: absolute;
right: 10px;
top: 10px;
color: black;" class="time icon ">
<i ng-class="{ 'ion-gear-b': data.paused, 'ion-loading-c spin': !data.paused}" class=" icon balanced" ng-click="showcard(item.id)"></i>
</div>
</span>
</ion-item>
</ion-list>
Controller
$scope.openTasks = function (impFlag, urgFlag) {
console.log("important came as: " + impFlag + " , urgent falg came as: " + urgFlag);
quadrantservice.gettask.get({
important: impFlag,
urgent: urgFlag
}).$promise.then(function (result) {
$scope.taskdetails = result;
console.log('task detailssssssssssssss' + JSON.stringify($scope.taskdetails));
/*$state.go('listoftask', {
important: impFlag,
urgent: urgFlag
});*/
});
$state.go('/listostasks');
}
I am getting the data in console but I am not able to display it on 'listoftasks' state.

You need $watch on your data change because intially data is not available so you need to watch the changes and reflect it accordingly.
$scope.$watch('taskdetails',function(newVal){
if(typeof newVal !='undefined'){
$scope.taskdetails=newVal;
}
});
//Place this in your maincontroller.

Related

how to toggle a checkbox with no id using protractor

I am new into protractor e2e. I am trying to toggle a checkbox with no id. How do I get the value if the checkbox is checked or not?
<div class="bootstrap-switch bootstrap-switch-wrapper bootstrap-switch-mini bootstrap-switch-on bootstrap-switch-animate" style="width: 62px;">
<div class="bootstrap-switch-container" style="width: 90px; margin-left: 0px;">
<span class="bootstrap-switch-handle-on bootstrap-switch-success" style="width: 30px;">Yes</span>
<span class="bootstrap-switch-label" style="width: 30px;"> </span>
<span class="bootstrap-switch-handle-off bootstrap-switch-danger" style="width: 30px;">No</span>
<input type="checkbox" data-bind="bootstrapSwitchOn: IsActive, v1:$root.isenable" data-on-text="Yes" data-off-text="No" data-size="mini" data-handle-width="20px" data-label-width="20px" data-on-color="success" data-off-color="danger">
</div>
</div>
<label class="checkbox-inline" data-bind="text: window.LabelVM.workflow_details_active,attr: { 'data-title': window.LabelVM.workflow_details_active, 'data-con': window.LabelVM.Active_popover, 'data-popover': 'popover' }" data-tab="3" data-orientation="right" data-title="Is Active" data-con="Activate your workflow for it to appear in Self Service. If a Workflow isn&#39;t active, it cannot be accessed by a staff member" data-popover="popover">Is Active</label>
You should try making your check to be based on the presence of the bootstrap-switch-on class that I assume indicates that the checkbox is set/checked.
Something along these lines:
function checkValue (checkbox) {
checkbox.getAttribute("class").then(function (classes) {
var switchOn = classes.indexOf("bootstrap-switch-on") >= 0;
if (switchOn) {
console.log("Switch is on");
} else {
console.log("Switch is off");
}
});
}
var checkbox = $(".bootstrap-switch");
checkValue(checkbox);
checkbox.click();
checkValue(checkbox);
(not tested)

Custom Filtering Shared Data in Angular

I'm trying to filter data from a factory that can becontrolled by booleans. I can't figure out what I'm doing wrong. It's probally the syntax and myself not understanding angular right. but I've been frozen here fror a while and cannot get past. I'm showing a product list and filter it through ng-repeat directive and custom filter.
.filter('promos'[
'$scope', '$http', 'FilterData', 'ProductData', function(
$scope, $http, FilterData, ProductData){
$scope.filterData = FilterData;
$scope.products = ProductData;
angular.forEach(products, function(product){
var promoProducts = [];
//booleen filters- if all or none selected do nothing - full product list
if ($scope.filterData.topChoices[0].selected && $scope.filterData.topChoices[1].selected && $scope.filterData.topChoices[2].selected || $scope.filterData.topChoices[0].selected === false && $scope.filterData.topChoices[1].selected === false && $scope.filterData.topChoices[2].selected === false ) {}
else {
//if option selects, show corresponding products
if ($scope.filterData.topChoices[0].selected && product.onPromotion) {promoProducts.push}
if ($scope.filterData.topChoices[1].selected && product.hotSeller) {promoProducts.push}
if ($scope.filterData.topChoices[2].selected && product.freeShip) {promoProducts.push}
return promoProducts;
}
});
}])
Controller & Factories can be seen in the plunker [http://plnkr.co/edit/EDZPOPh7iMFSpPjO6AkI?p=preview][1]
Here is the html:
<div ng-controller="prodCtrl">
<md-input-container class="md-icon-float md-icon-right md-block">
<label>Low Price</label>
<md-icon md-font-icon="fa fa-money"></md-icon>
<input ng-model="filterData.price.low" type="number" step="5">
<md-icon md-svg-src="img/icons/ic_euro_24px.svg"></md-icon>
</md-input-container>
<md-input-container class="md-icon-float md-icon-right md-block">
<label>High Price</label>
<md-icon md-font-icon="fa fa-money"></md-icon>
<input ng-model="filterData.price.high" type="number" step="5">
<md-icon md-svg-src="img/icons/ic_euro_24px.svg"></md-icon>
</md-input-container>
<md-checkbox style="margin-left: 15px;" class="md-secondary" ng-model="filterData.topChoices[0].selected"> Show Promotions <br><span style="font-size: 10px; color: blue;" ng-if="filterData.topChoices[0].selected">selected</span> </md-checkbox>
<md-checkbox style="margin-left: 15px;" class="md-secondary" ng-model="filterData.topChoices[1].selected"> Show Hot Sellers<br><span style="font-size: 10px; color: blue;" ng-if="filterData.topChoices[1].selected">selected</span> </md-checkbox>
<md-checkbox style="margin-left: 15px;" class="md-secondary" ng-model="filterData.topChoices[2].selected"> Show Free Shipping<br><span style="font-size: 10px; color: blue;" ng-if="filterData.topChoices[2].selected">selected</span> </md-checkbox>
</div>
<md-subheader class="md-no-sticky">Avatar with Secondary Action Icon</md-subheader>
<md-list ng-Controller="prodCtrl">
<md-list-item ng-repeat="product in products | filter:promos" ng-click class="noright">
<ul>
<h3>{{product.name}} </h3>
<p>{{product.desc}}</p>
</ul>
<ul class="md-secondary">
<li style="list-style: none;" ng-if="product.onPromotion">On Promotion!</li>
<li style="list-style: none;" ng-if="product.hotSeller">Hot-Seller!</li>
<li style="list-style: none;" ng-if="product.freeShip">Free Shipping!</li>
</ul>
<ul class="md-secondary" style="margin-right: 25px;">
<li style="list-style: none;" ng-repeat="item in product.sellers | orderBy: item.price">
{{item.seller}} ${{item.price}}</li>
</ul>
<md-button class="md-raised md-primary md-secondary">Buy</md-button>
</md-list-item>
</md-list>
Please help put me on the right direction. I'm usuing a factory because i also use the product data in a map. So I'm thinking this is the best route.
This will go inside you filter code
remove $http and $scope dependencies from the filter
heres a working fiddle
var pusher = function(main, toPush) {
var alreadyPresent = false;
angular.forEach(main, function(toCheck) {
if (toCheck === toPush) {
alreadyPresent = true;
}
})
if (!alreadyPresent) {
main.push(toPush);
}
}
var p = [];
angular.forEach(products, function(product) {
if (FilterData.topChoices[0].selected &&
FilterData.topChoices[1].selected && FilterData.topChoices[2].selected || FilterData.topChoices[0].selected === false && FilterData.topChoices[1].selected === false && FilterData.topChoices[2].selected === false) {} else {
//if
if (FilterData.topChoices[0].selected && product.onPromotion) {
pusher(p, product);
}
if (FilterData.topChoices[1].selected && product.hotSeller) {
pusher(p, product);
}
if (FilterData.topChoices[2].selected && product.freeShip) {
pusher(p, product);
}
console.log('ppp')
console.log(p);
console.log('--ppp')
}
})
return p;
and to use the filter do
<md-list-item ng-repeat="product in products | promo" ng-click class="noright">

add controller to a angular-tiny template

I'm trying to use tinyMCE in my angualar app. I'm using the directive provided by angular-ui-tinymce module. I have a state in wich i put the textarea and i want to buitd some templates that the user can choice. Moreover, I want to make dynamic these template. Here is my controller :
(function(){
'use strict';
angular
.module('app.core')
.controller('refertazioneController', refertazioneController);
function refertazioneController($stateParams){
var vm = this;
vm.prova="refertazioneController";
vm.tinymceModel = '';
vm.sospeso=true;
vm.params = $stateParams;
vm.currentUser = sessionStorage;
vm.tinymceOptions = {
inline: false,
slector: 'textarea',
height: 500,
plugins : 'advlist autolink link image lists charmap print preview template save',
skin: 'lightgray',
theme : 'modern',
language:'it',
statusbar: false,
templates:[ {title: 'Titolo1', description: 'Descrizione1', url: 'sections/refertazione/referto1.html'},
{title: 'Titolo2', description: 'Secondo referto', url: 'sections/refertazione/referto1.html'}
]
};
}
})();
and this is the template:
<p style="text-align: center;">
<strong>A.S.L. 02 LANCIANO-VASTO-CHIETI</strong>
</p>
<p style="text-align: center;">
<strong>Ospedale Clinicizzato "SS.Annunziata"</strong>
</p>
<p style="text-align: center;">
<strong>Servizio Radiologia</strong>
</p>
<p style="text-align: center;">
<strong>Sezione di Scienze Radiologiche dell Università </strong>
</p>
<p style="text-align: center;">Direttore: Prof. Antonio Raffaele Cotroneo</p>
the problem is that I can not use my controller in the template. I tryed to handle the template like a state in ui router but the same. Can someone suggest me an approach?
Why wouldn't this work?
<div ng-controller="refertazioneController as referCtrl">
<p style="text-align: center;">
<strong>A.S.L. 02 LANCIANO-VASTO-CHIETI</strong>
</p>
<p style="text-align: center;">
<strong>Ospedale Clinicizzato "SS.Annunziata"</strong>
</p>
<p style="text-align: center;">
<strong>Servizio Radiologia</strong>
</p>
<p style="text-align: center;">
<strong>Sezione di Scienze Radiologiche dell Università </strong>
</p>
<p style="text-align: center;">Direttore: Prof. Antonio Raffaele Cotroneo</p>
</div>

Collection repeat list inside Ionic Pop Up

I have a collection repeat list with a search bar on top of the list (that is inside ionic pop up body). On the real device (Android 4.4), the list displays only 9 records.
I have a codepen created collection repeat inside ionic pop up. Here it displays all the records, but not on the actual device.
Recently I updated from Ionic 1.1.1 to Ionic 1.2.4 . Is it a problem because of the new Ionic version, I also tried Ionic 1.2.4's nightly build it also dint work.
Does the phone's browser version cause a difference, My phone's browser version is "Mozilla/5.0(Linux 4.4.2; en-us; 6043D Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) version/4.0 chrome/ 30.0.0 Mobile Safari/537.36."
Here is the HTML code of the ionic pop up.
<div class="list list-inset" ng-style="{ 'display': 'inline-flex', 'padding': '0'}">
<label class='item item-input' ng-style='{ 'border-right-color': '#FFFFFF'}'>
<i class='icon icon-left ion-ios7-search placeholder-icon''></i>
<input type='text' ng-model='search' placeholder='Search'>
</label>
<a class='button button-icon icon ion-ios7-close-empty placeholder-icon'
ng-style='{ 'color': '#B83E2C' }'
on-touch='clearSearch()''>
</a>
</div>
<div class='listPopUpHeight'>
<ion-scroll direction="y" class="available-scroller" style="height:350px">
<ion-list>
<ion-item
class="dataSourceItem"
collection-repeat="item in dataSource | filter:search"
collection-item-width="100%"
item-height="15%"
on-tap="tapped(item)">
{{item.Text}}
</ion-item>
</ion-list>
</ion-scroll>
</div>
Here is the JS code:
angular.module('ionicApp', ['ionic'])
.controller('PopupCtrl', function($scope, $ionicPopup, $timeout) {
$scope.dataSource = [];
$scope.showList = function(){
var list=[];
for (var i = 0; i < 1000; i++) {
list.push({ 'Id': i, 'Text': 'Text_' + i });
}
$scope.dataSource = list;
var listPopup = $ionicPopup.show({
templateUrl: 'popupTemplate.html',
title: 'List',
scope: $scope,
buttons: [
{ text: 'Cancel' },
]
});
};
});
Is there something I am missing out. Kindly do reply.
Thanks in advance :)
Please check below link. I made a popup with radio button with searchbar for Ionic v1.
https://codepen.io/engabdalb/pen/LYpWbZa
HTML
<a class="item" ng-click="open('aracyakit.html')">
Yakıt
<span style="color:#0097A4" style="color:#0097A4" class="item-note" >
{{arackayit.araba_yakit}}
</span>
</a>
<script id='aracyakit.html' type='text/ng-template'>
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" ng-model="arama" placeholder="Arama">
</label>
<ion-radio name="araba_yakit" id="araba_yakit" ng-repeat="ay in arabayakitlari | filter:arama" class="wrapping-list" ng-model="arackayit.araba_yakit" ng-value="'{{ay.value}}'">{{ay.name}}</ion-radio>
</script>
<a class="item" ng-click="open('aracvites.html')">
Vites
<span style="color:#0097A4" style="color:#0097A4" class="item-note" >
{{arackayit.araba_vites}}
</span>
</a>
<script id='aracvites.html' type='text/ng-template'>
<label class="item item-input">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" ng-model="arama" placeholder="Arama">
</label>
<ion-radio name="araba_vites" id="araba_vites" ng-repeat="av in arabavitesleri | filter:arama" class="wrapping-list" ng-model="arackayit.araba_vites" ng-value="'{{av.value}}'">{{av.name}}</ion-radio>
</script>
CSS
.popup-body {
padding: 10px;
overflow: auto;
width: 100%;
}
.popup-open .popup-backdrop,
.popup-open .popup {
pointer-events: auto;
width: 100%;
}
.popup-head {
padding: 0px 0px;
border-bottom: 1px solid #eee;
text-align: center;
}
JS
$scope.arackayit = [];
$scope.arabavitesleri = [
{ value: "Otomatik", name: "Otomatik" },
{ value: "Manuel", name: "Manuel" }
]
$scope.arabayakitlari = [
{ value: "Dizel", name: "Dizel" },
{ value: "Benzin", name: "Benzin" },
{ value: "Benzin-LPG", name: "Benzin-LPG" }
]
$scope.open = function(clicked) {
$ionicPopup.confirm({
templateUrl: clicked,
scope: $scope,
buttons: [{
text: 'Iptal',
type: 'button-default',
onTap: function(e) {
// Change/ write here current page
$state.go('tab.aracekle');
}
}, {
text: 'Tamam',
type: 'button-positive',
onTap: function(e) {
//open next when OK clicked
switch (clicked) {
case 'aracyakit.html':
$scope.open('aracvites.html');
break;
//Do nothing when OK clicked
case 'aracvites.html':
default:
// code block
}
}
}]
});
}

How do I make the carousel indicators in angular ui use thumbnails from a model in a controller?

I'm using the angular ui bootstrap carousel and I want to make the indicators thumbnails. I have a controller that looks like this (from the demo):
function carouselCtrl($scope) {
$scope.myInterval = 5000;
$scope.imgPath="img/slideshow/"
var slides = $scope.slides = [{
'imgName':'iguanas.jpg',
'caption':'Marine iguanas in the Galapagos National Park on Santa Cruz Island, on September 15, 2008.',
'author':'(Reuters/Guillermo Granja)'
},{
'imgName':'eruption.jpg',
'caption':'In June of 2009, the Cerro Azul volcano on Isabela Island was in an active phase, spewing molten lava into the air, spilling it across its flanks, and widening existing lava flows.',
'author':'(Reuters/Parque Nacional Galapagos)'
},{
'imgName':'bluefoot.jpg',
'caption':'A close-up of a pair of Booby feet, photographed in March of 2008. ',
'author':'(CC BY Michael McCullough)'
}];
}
and the template looks like this:
<div ng-mouseenter="pause()" ng-mouseleave="play()" class="carousel">
<ul class="carousel-indicators" ng-show="slides().length > 1">
<li ng-repeat="slide in slides()" class="slide-thumb" ng-class="{active: isActive(slide)}" ng-click="select(slide)"></li>
</ul>
<div class="carousel-inner" ng-transclude></div>
<a ng-click="prev()" class="carousel-control left" ng-show="slides().length > 1">‹</a>
<a ng-click="next()" class="carousel-control right" ng-show="slides().length > 1">›</a>
</div>
I want to do something like this:
<li ng-repeat="slide in slides()" class="slide-thumb" ng-class="{active: isActive(slide)}" ng-click="select(slide)" style="background-image:url({{slide.imgName}});"></li>
but I must be out of scope or something... Does anyone know any angular carousels that have a thumbnail option or how I can get this to work?
The slide array in the carousel template actually don't refer to the slides array you have defined in your app controller.
In the carousel template slides refer to a bunch of dom elements enhanced with internal properties. That's why any access to properties you have defined in our objects will failed when executed (scope issue as you guessed already).
If you want to stick to the carousel from angular-ui I would recommend a slightly different approach and go for css styling something like that:
//Default styles for indicator elements
.carousel-indicators li {
background-size : 42px 22px;
width : 42px;
height: 22px;
background-repeat : no-repeat;
background-position : center;
cursor : pointer;
}
// Then Specify a background image for every slide
.carousel-indicators li:nth-child(1){
background-image: url(http://cache.wallpaperdownloader.com/bing/img/WeddedRocks_20100418.jpg);
}
...
You can see a working Plunker here.
It's very possible and it's very simple. First you must pass the model of every slide in the actual directive as indicated in the docs for the uib-slide settings. And then you must override the template using the template-url directive. Don't forget to declare the template.
So the html should look like this:
<!--Defining the controller scope-->
<div ng-controller="carousel">
<!--Declaring the template for later usage-->
<script id="carousel-with-thumbs.html" type="text/ng-template">
<div ng-mouseenter="pause()" ng-mouseleave="play()" class="carousel" ng-swipe-right="prev()"
ng-swipe-left="next()">
<div class="carousel-inner" ng-transclude></div>
<a role="button" href class="left carousel-control" ng-click="prev()"
ng-class="{ disabled: isPrevDisabled() }"
ng-show="slides.length > 1">
<span aria-hidden="true" class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">previous</span>
</a>
<a role="button" href class="right carousel-control" ng-click="next()"
ng-class="{ disabled: isNextDisabled() }"
ng-show="slides.length > 1">
<span aria-hidden="true" class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">next</span>
</a>
<ol class="carousel-indicators" ng-show="slides.length > 1">
<li ng-repeat="slide in slides | orderBy:indexOfSlide track by $index"
ng-class="{ active: isActive(slide) }" ng-click="select(slide)">
<!--Showing the thumbnail in a <img> tag -->
<img ng-src="{{slide.slide.actual.thumb}}">
<span class="sr-only">slide {{ $index + 1 }} of {{ slides.length }}<span ng-if="isActive(slide)">, currently active</span></span>
</li>
</ol>
</div>
</div>
</script>
<uib-carousel active="active" interval="interval" template-url="carousel-with-thumbs.html">
<uib-slide ng-repeat="slide in slides track by $index" index="$index" actual="slide">
<!--Passing the slide in the actual directive-->
<img ng-src="{{slide.image}}" style="margin:auto;">
<div class="carousel-caption">
<h4>{{slide.title}}</h4>
<p>{{slide.text}}</p>
</div>
</uib-slide>
</uib-carousel>
Take a moment to analyse the carousel-indicators ordered list:
<ol class="carousel-indicators" ng-show="slides.length > 1">
<li ng-repeat="slide in slides | orderBy:indexOfSlide track by $index" ng-class="{ active: isActive(slide) }"
ng-click="select(slide)">
<img ng-src="{{slide.slide.actual.thumb}}">
<span class="sr-only">slide {{ $index + 1 }} of {{ slides.length }}<span ng-if="isActive(slide)">, currently active</span></span>
</li>
</ol>
Look how each slide model has another slide sub-model which is the transcluded scope of the slide model passed
through the actual directive. And then, nested again, the actual model containing all the data of each slide:
<img ng-src="{{slide.slide.actual.thumb}}">
And of course for the big finale, the controller should look like this:
(function(){
'use strict';
angular
.module('app', ['ui.bootstrap'])
.controller('carousel', carousel);
carousel.$inject = ['$scope'];
function carousel($scope){
$scope.active = 0;
$scope.interval = 5000;
$scope.slides = [
{title: "Any title", text: "This is a text for the slide", image: "path/to/the/image/image.jpg", thumb: "path/to/the/image/thumbs/thumb.jpg"},
{title: "Any title", text: "This is a text for the slide", image: "path/to/the/image/image.jpg", thumb: "path/to/the/image/thumbs/thumb.jpg"},
{title: "Any title", text: "This is a text for the slide", image: "path/to/the/image/image.jpg", thumb: "path/to/the/image/thumbs/thumb.jpg"}
];
}
})();
By the way, I'm using Angular UI Boostrap 1.3.3 along with Angular 1.5.8.
Here's the Fiddle for it https://jsfiddle.net/logus/6mvjpf40/

Resources