Angular ng-click onsen - angularjs

So im new to coding and i cant seem to figure out some issue that i have.
<ons-row ng-click="myNavigator.pushPage('{{building.file}}.html')">
So i started and the {{ building.file }} isn't going to the url. can someone help me or explain why it isnt workking? here is my complete code
<div ng-init="buildings = [
{name:'name1',file:'file1', location:'location1', image:'images/img1.jpg', number:'(123) 400-0000'},
{name:'name2',file:'file2', location:'location2', image:'images/img2.jpg', number:'(123) 400-0000'},
{name:'name3',file:'file3', location:'location3', image:'images/img3.jpg', number:'(123) 400-0000'},
]">
<!--There Are {{buildings.length}} restaurants-->
<input type="search" ng-model="q" class="search-input" placeholder="Search..." />
<br />
<ons-list >
<ons-list-item modifier="chevron" class="list-item-container" ng-repeat="building in buildings | filter:q as results">
<ons-row ng-click="myNavigator.pushPage('/' + {{building.file}} + '.html')">
<ons-col width="95px">
<img src="{{building.image}}" class="thumbnail">
</ons-col>
<ons-col>
<div class="name">
{{building.name}}
</div>
<div class="location">
<i class="fa fa-map-marker"></i> {{building.location}}
</div>
<div class="desc">
{{building.number}}
</div>
</ons-col>
<ons-col width="40px"></ons-col>
</ons-row>
</ons-list-item>
</ons-list>
<ul class="example-animate-container">
<li class="animate-repeat" ng-if="results.length == 0">
<strong>No results found...</strong>
</li>
<li class="animate-repeat" ng-if="results.length == 555">
<strong>No results found...</strong>
</li>
</ul>

I don't have your exact code but i think u should not use expression within function call. I created sample demonstration for your app Demo. Please check on console by clicking on name. it logs correct url. Hope this helps!
<div ng-click="pushPage('/' + building.file + '.html')">
{{building.name}}
</div>

I don't see the ons-navigator in your code. The easiest way in angular is to use a var for ons-navigator and then you can use myNavigator.pushPage('name')
<ons-navigator var="myNavigator">
<ons-page>
<ons-row ng-click="myNavigator.pushPage('file.html')" > My Row </ons-row>
</ons-page>
</ons-navigator>
<ons-template id="file.html">
<ons-page>
My Content
</ons-page>
</ons-template>

Related

pass value from one ons-template to another using angular js [Onsen UI]

I want some values from one ons-template to another, i have tried sending values from ons-template to controller and getting back to another ons-template from a controller, but is there any way i can get the values directly from one ons-template to another without calling the controller? Below is my code.
sendmoney.html
<ons-template id="sendmoney.html">
<ons-page modifier="shop-details" class='page_bg'>
<ons-toolbar style="background-color: #16A500;">
<div class="left">
<ons-toolbar-button ng-click="menu.openMenu();">
<ons-icon icon="ion-navicon" size="28px" fixed-width="false"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center">Send Money</div>
<div class="right">
<ons-toolbar-button onclick="doContactPicker()">
<ons-icon icon="ion-plus" size="28px" fixed-width="false"></ons-icon>
</ons-toolbar-button>
</div>
</ons-toolbar>
<div ng-controller="getUserContacts">
<ons-list-header>Select Contact</ons-list-header>
<ons-list style="margin: -1px 0">
<div ng-show="loading" class="loading"><img src="img/loading.gif" height="50px" width="50px"></div>
<ons-list-item modifier="chevron" class="list-item" ng-repeat="x in contacts track by $index" style="margin-left: 10px;" ng-click="page.pushPage('sendmoney2.html', {animation: 'slide'});">
<ons-row>
<ons-col width="52px" style="padding: 10px 0 0 0;">
<img src="img/red.png" height="42px" width="42px"/>
</ons-col>
<ons-col>
<header>
<span class="item-title">{{x.name}}</span>
</header>
<p class="swipe-item-desc">{{x.phone}}</p>
</ons-col>
</ons-row>
</ons-list-item>
</ons-list>
</div>
</ons-page>
</ons-template>
I want {{x.name}} and {{x.phone}} in sendmoney2.html template
sendmoney2.html
<ons-template id="sendmoney2.html">
<ons-page modifier="shop-details" class='page_bg'>
<ons-toolbar style="background-color: #16A500;">
<div class="left">
<ons-toolbar-button ng-click="menu.openMenu();">
<ons-icon icon="ion-navicon" size="28px" fixed-width="false"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center">Send Money</div>
</ons-toolbar>
</ons-page>
</ons-template
I don't know Angular very well, but in plain JS, you simply set a global variable to get around this. I think of the app design as just one large web page. That often helps me solve my problems. So basically just define these in the top of your script:
var vName = '';
var vPhone = '';
Then set them in the events, this should work.

Tab bar makes the page unclickable

When i add a ons-tabbar to my page it overlaps my entire page so that i can't click on anything except the tabs itself.
My page looks like the following (each page has it own html file):
<ons-page>
<ons-tabbar>
<label class="tab-bar__item">
<input type="radio" name="tab-bar-a" checked="checked">
<button class="tab-bar__button">
<i class="tab-bar__icon fa fa-dashboard"></i>
<div class="tab-bar__label">Dashboard</div>
</button>
</label>
<label class="tab-bar__item" ng-click="myNav.pushPage('views/device-settings.html', {animation : 'slide'})">
<button class="tab-bar__button">
<i class="tab-bar__icon fa fa-cogs"></i>
<div class="tab-bar__label">Settings</div>
</button>
</label>
</ons-tabbar>
<ons-toolbar>
<div class="left">
<ons-toolbar-button ng-click="menu.toggle()">
<ons-icon icon="ion-navicon" size="28px" fixed-width="false"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center">Device</div>
</ons-toolbar>
<ons-list id="device">
<ons-list-item>
<label class="checkbox">
<input type="checkbox" checked="checked">
<div class="checkbox__checkmark"></div>
Switch 1
</label>
<div class="switch-detail">
<ons-icon icon="fa-calendar"></ons-icon>
Last enabled: 9 February 2016 on 17:39
</div>
</ons-list-item>
<ons-list-item>
<label class="checkbox">
<input type="checkbox" checked="checked">
<div class="checkbox__checkmark"></div>
Switch 2
</label>
<div class="switch-detail">
<ons-icon icon="fa-calendar"></ons-icon>
Last enabled: 9 February 2016 on 17:39
</div>
</ons-list-item>
<ons-list-item>
<label class="checkbox">
<input type="checkbox" checked="checked">
<div class="checkbox__checkmark"></div>
Switch 3
</label>
<div class="switch-detail">
<ons-icon icon="fa-calendar"></ons-icon>
Last enabled: 9 February 2016 on 17:39
</div>
</ons-list-item>
</ons-list>
Don't implement ons-tabbar like that, use the following syntax:
<ons-tabbar>
<ons-tab>tab1</ons-tab>
<ons-tab>tab2</ons-tab>
</ons-tabbar>
Also, try to implement the ons-tabbar outside ons-page and link the single ons-tab to the relative page (using ons-template):
<ons-tabbar>
<ons-tab page="home.html" active="true">
<ons-icon icon="ion-home"></ons-icon>
<span style="font-size: 14px">Home</span>
</ons-tab>
<ons-tab page="fav.html" active="true">
<ons-icon icon="ion-star"></ons-icon>
<span style="font-size: 14px">Favorites</span>
</ons-tab>
<ons-tab page="settings.html" active="true">
<ons-icon icon="ion-gear-a"></ons-icon>
<span style="font-size: 14px">Settings</span>
</ons-tab>
</ons-tabbar>
<ons-template id="home.html>
<ons-page>
PAGE CONTENT
</ons-page>
</ons-template>
Here is a working CodePen example, based on your code:
http://codepen.io/andipavllo/pen/rxQEeY
Hope it helps!
ons-tabbar has children of kind ons-tab. You give the content of the lower tabbar icon array as a content and have to give the content of the page as an parameter id of page="ID".
<ons-tabbar var="tabbar" animation="fade">
<ons-tab
active="true"
icon="ion-chatbox-working"
label="Comments"
page="page1.html">
</ons-tab>
<ons-tab
icon="ion-ios-cog"
label="Settings"
page="page2.html">
</ons-tab>
</ons-tabbar>
<ons-template id="page1.html" >
<ons-toolbar>
<div class="center">Page 1</div>
</ons-toolbar>
</ons-template>
<ons-template id="page2.html" >
<ons-toolbar>
<div class="center">Page 2</div>
</ons-toolbar>
</ons-template>
Here is some working codePen:
http://codepen.io/anon/pen/yeQdMX

Onsen Ui & AngularJs: Delayed function after swipe gesture

I´m using the swipe gesture to navigat to a page / template.
If I swipe to the left, I want to fade in / fade out the like-col for 5 Seconds.
If I swipe to the right, I want to fade in / fade out the pass-col for 5 Seconds.
After fading out the like-col or pass-col, both gestures should navigate to the template match1.html.
Currently the columns appear shortly after 5 seconds and it goes directly to the template match1.html
What am I doing wrong? Thank you for your tips.
var app = angular.module('myApp', ['onsen', 'ngSanitize', 'ngRoute', 'onsen.directives', 'ngTagsInput']);
app.controller('findPatientsController', function($scope, $route, $window, $timeout) {
$scope.startFindPatient = function() {
$timeout(function() {
findPatientsNavigator.pushPage('match1.html', {
animation: 'slide'
});
}, 1000);
};
$scope.swipe = {
active: false
};
$scope.onGestureMatch1 = function(gesture) {
if (gesture == 'Swipe Left') {
console.log('like');
$scope.swipe.like = !$scope.swipe.like;
$timeout(function() {
findPatientsNavigator.pushPage('match2.html', {
animation: 'slide'
});
}, 5000);
}
if (gesture == 'Swipe Right') {
console.log('pass');
$scope.swipe.pass = !$scope.swipe.pass;
$timeout(function() {
findPatientsNavigator.pushPage('match2.html', {
animation: 'slide'
});
}, 5000);
}
}
});
<ons-navigator animation="slide" ng-controller="findPatientsController" var="findPatientsNavigator">
<ons-page id="introFindPatientsPage">
<ons-toolbar>
<div class="left">
<ons-toolbar-button ng-click="slidingMenu.toggleMenu()">
<ons-icon icon="bars"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center">
Schnellsuche
</div>
</ons-toolbar>
<ons-gesture-detector ng-swipeleft="onGestureStart('Swipe Left')" ng-swiperight="onGestureStart('Swipe Right')">
<div id="detect-area" style="width: 100%; height: 500px;">
<div class="searchInfo" ng-init="startFindPatient()">
<span class="searchText"><i class="fa fa-search"></i> Search...</span>
</div>
</div>
</ons-gesture-detector>
</ons-page>
<ons-template id="match1.html">
<ons-page id="match1Page">
<ons-toolbar>
<div class="left">
<ons-toolbar-button ng-click="slidingMenu.toggleMenu()">
<ons-icon icon="bars"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center">
Neuer Match
</div>
</ons-toolbar>
<ons-gesture-detector ng-swipeleft="onGestureMatch1('Swipe Left')" ng-swiperight="onGestureMatch1('Swipe Right')">
<ons-row class="swipeRow">
<ons-col width="80px" ng-show="swipe.like" class="like-col col ons-col-inner">
<div class="info-unit">
<ons-icon icon="fa fa-star fa-likePass"></ons-icon>
</div>
</ons-col>
<ons-col class="id-col col ons-col-inner">
<div class="newMatch-id">peterson</div>
<div class="newMatch-birthdate">40 Jahre</div>
</ons-col>
<ons-col width="80px" ng-show="swipe.pass" class="pass-col col ons-col-inner">
<div class="info-unit">
<ons-icon icon="fa fa-times fa-likePass"></ons-icon>
</div>
</ons-col>
</ons-row>
<div class="newMatch">
<div ng-controller="GaugeController">
<div gauge-chart percent="matchGauge1"></div>
</div>
<ons-row>
<div class="matching-list-item-container">
<div class="heading-matching-list"><i class="fa fa-stethoscope"></i> Übereinstimmungen</div>
<div ng-controller="tagsMatchingController" class="matchingTag">
<div class="tags">
<ul class="tag-list">
<li class="tag-item">
<span class="ng-binding">Radiusfraktur</span>
</li>
<li class="tag-item">
<span class="ng-binding">Karpaltunnelsyndrom</span>
</li>
<li class="tag-item">
<span class="ng-binding">Ulnarisrinnen-Syndrom</span>
</li>
</ul>
</div>
</div>
</div>
</div>
</ons-row>
</ons-gesture-detector>
</ons-page>
</ons-template>
<ons-template id="match2.html">
<ons-page id="match2Page">
<ons-toolbar>
<div class="left">
<ons-toolbar-button ng-click="slidingMenu.toggleMenu()">
<ons-icon icon="bars"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center">
Neuer Match
</div>
</ons-toolbar>
<ons-gesture-detector ng-swipeleft="onGestureMatch2('Swipe Left')" ng-swiperight="onGestureMatch2('Swipe Right')">
<div class="newMatch">
<div class="newMatch-id">findus</div>
<div class="newMatch-birthdate">32 Jahre</div>
<div ng-controller="GaugeController">
<div gauge-chart percent="matchGauge2"></div>
</div>
<ons-row>
<div class="matching-list-item-container">
<div class="heading-matching-list"><i class="fa fa-stethoscope"></i> Übereinstimmungen</div>
<div ng-controller="tagsMatchingController" class="matchingTag">
<div class="tags">
<ul class="tag-list">
<li class="tag-item">
<span class="ng-binding">Radiusfraktur</span>
</li>
<li class="tag-item">
<span class="ng-binding">Ulnarisrinnen-Syndrom</span>
</li>
</ul>
</div>
</div>
</div>
</div>
</ons-row>
</ons-gesture-detector>
</ons-page>
</ons-template>
</ons-navigator>

Onsen carousel & template with json

I have an Onsen-UI template/index where I have a carousel and have each carousel-item calling a ons-template id (html). One of those templates is calling for ng-controller (which is calling for json api) and has usual javascript within it.
If I view the index.html in Chrome, the list shows but when I build it as phonegap app and run the apk on my android device, the list never appears. It just loads in a loop without 'loading' it.
Also, when I click on a list item it should take me to another html template to display the correct information and where (page.html), which Chrome doesn't do (could be just an issue in chrome).
I'm hoping if I get the list to display on my app, then the second part would fix itself or do I need to do some extra tweaking?
Here is my template code calling the controller:
<ons-template id="news.html">
<ons-page>
<div class="app-page opacity-bar">
<div class="app-page-content">
<div class="app-page news-page" ng-controller="newsController" data-ng-init="getAllRecords()">
<ons-list modifier="news">
<ons-list-item modifier="chevron" class="list-item-container" ng-repeat="item in items" ng-click="showPost($index)">
<ons-row>
<ons-col width="95px">
<img ng-show="{{ item.thumbnail_images }}" ng-src="{{ item.thumbnail_images.thumbnail.url }}" class="thumbnail">
</ons-col>
<ons-col>
<div class="name">
{{ item.title | limitTo: 15 }}...
</div>
<div class="location" ng-show="{{ item.categories }}">
<i class="ion-pricetags"></i> <span ng-repeat="cat in item.categories">{{cat.title}} </span>
</div>
<div class="desc">
{{ item.excerpt | htmlToPlaintext | limitTo: 60 }}...
</div>
</ons-col>
<ons-col width="40px"></ons-col>
</ons-row>
</ons-list-item>
</ons-list>
<ons-button id="moreButton" modifier="large" should-spin="{{isFetching}}" ng-click="nextPage()">more news</ons-button>
</div></div></div>
</ons-page>
</ons-template>
The carousel is very weak, bad implemented, i have same issue too, and the support is NULL
May be this link will help for you, Check with the code
<ons-page>
<ons-toolbar>
<div class="center">Carousel</div>
</ons-toolbar>
<ons-carousel ng-controller="CarouselController" swipeable auto-scroll fullscreen var="carousel">
<ons-carousel-item style="background-color: gray;">
<div class="item-label">GRAY</div>
</ons-carousel-item>
<ons-carousel-item style="background-color: #085078;">
<div class="item-label">BLUE</div>
</ons-carousel-item>
<ons-carousel-item style="background-color: #373B44;">
<div class="item-label">DARK</div>
</ons-carousel-item>
<ons-carousel-item style="background-color: #D38312;">
<div class="item-label">ORANGE</div>
</ons-carousel-item>
<ons-carousel-cover>
<div class="bullets">
<span
ng-repeat="idx in indices"
ng-class="{'active': idx === carousel.getActiveCarouselItemIndex()}">
•
</span>
</div>
</ons-carousel-cover>
</ons-carousel>
</ons-page>

Doesn't show div in onsen ui and angularjs

in my app i try to show my search div into my toolbar. Now my searchbar is outside from my toolbar and works fine (show and hide when i click on my search button). When i try to put my searchbar into my toolbar my search button doesnt work (doesnt show).
My html code:
<ons-page ng-controller="alojamientosController" data-ng-init="getAllRecords()">
<ons-toolbar>
<div class="left">
<ons-toolbar-button ng-click="menu.toggle()"><ons-icon icon="ion-navicon-round" fixed-width="false"></ons-icon></ons-toolbar-button>
</div>
<div class="right">
<ons-toolbar-button ng-click="collapse()" ><ons-icon icon="ion-android-search"></ons-icon></ons-toolbar-button>
</div>
<div class="center">Alojamientos</div>
</ons-toolbar>
<div class="searchbar">
<input ng-show="collapsed" type="search" class="search-input" ng-model="search" placeholder="Buscar">
</div>
<div class="app-page alojamientos-page">
<ons-list modifier="news">
<ons-list-item modifier="chevron" class="list-item-container" ng-repeat="item in items | filter:search" ng-click="showPost(item)">
<ons-row>
<div class="thumbnail-box is-loading" images-loaded="imgLoadedEvents">
<img ng-show="{{ item.thumbnail_images }}" ng-src="{{ item.thumbnail_images.full.url }}" class="thumbnail" img-cache>
</div>
</ons-row>
<ons-row>
<div class="cabecera">
<div class="name">
{{ item.title | limitTo: 25 }}
</div>
<div class="location" ng-show="{{ item.categories }}">
</div>
</div>
</ons-row>
</ons-list-item>
</ons-list>
<ons-button id="moreButton" modifier="large" should-spin="{{isFetching}}" ng-click="nextPage()">more news</ons-button>
</div>
</ons-page>
app.js
$scope.collapsed = false;
$scope.collapse = function(){
return $scope.collapsed=!$scope.collapsed;
}
web example in "alojamientos" menu item: http://recorramisiones.com.ar/rutadelaselva/app2/
Thanks a lot
If you really want to put it into the toolbar, I think it should be inside one of the three position classes, something like this:
<div class="center">Alojamientos
<div class="searchbar" style="position:absolute; left:0; right:0">
<input ng-show="collapsed" type="search" class="search-input" ng-model="search" placeholder="Buscar">
</div>
</div>
Then you can use ng-style or ng-class to increase and decrease the height of the toolbar when you show or hide the searchbar and change anything else you need.
Another possibility would be to give to your searchbar's div the appearance of the toolbar with class="navigation-bar searchbar", and then delete the bottom border of the actual toolbar and adjust anything you need.

Resources