there is a bug that is ons-tab not work in my program - onsen-ui

My code as follows, when I click tab button "Ratios", it does not work,but when I click "Notes", it works.Actually,when I change the sequence of ons-template, such as ons-template sequence is "price.html","notes.html","ratios.html",the result is when I click tab button "notes", it does not work,but when I click "Ratios", it works.
Anybody knows the reason?
<ons-page ng-controller="myPortfoliosController">
<ons-toolbar class="DCF">
<div class="left">
<ons-back-button style="color:white;"></ons-back-button>
</div>
<div class="center" style="font-size:22px;" >My Portfolios</div>
</ons-toolbar>
<ons-tabbar position="top">
<ons-tab page="price.html" active="true">Price</ons-tab>
<ons-tab page="ratios.html">Ratios</ons-tab>
<ons-tab page="notes.html" >Notes</ons-tab>
</ons-tabbar>
<ons-template id="price.html">
<ons-page ng-controller="portPrice">
<div class="row" style="height:20px;background-color: #144A88;color:white;font-size: 14px;width: 100%;padding-left: 10px;">
<div class="col-xs-6 col-sm-3" style="width:35%;">Stock Symbol</div>
<div class="col-xs-6 col-sm-3" style="width:20%;">Current</div>
<div class="col-xs-6 col-sm-3" style="width:25%;">Purchased</div>
<div class="col-xs-6 col-sm-3" style="width:20%;">Change</div>
</div>
<div ng-repeat="portfolio in portfoliosList">
<div class="portname_{{portfolio.backgroundColor}}">{{portfolio.portname}}</div>
<div ng-repeat="portfolioStock in portfolio['detail']">
<div class="row">
<div class="col-xs-6 col-sm-3" style="width:40%;border-bottom:1px dashed #c0c0c0;">{{portfolioStock.symbol}}</div>
<div class="col-xs-6 col-sm-3" style="width:20%;border-bottom:1px dashed #c0c0c0;">{{portfolioStock.price}}</div>
<div class="col-xs-6 col-sm-3" style="width:20%;border-bottom:1px dashed #c0c0c0;">{{portfolioStock.in_price}}</div>
<div class="col-xs-6 col-sm-3" style="width:20%;border-bottom:1px dashed #c0c0c0;color:{{portfolioStock.font_color}}">{{portfolioStock.gain_p}}</div>
</div>
</div>
</div>
</ons-page>
</ons-template>
<ons-template id="ratios.html">
<ons-page ng-controller="portRatios">
<div class="row" style="height:20px;background-color: #144A88;color:white;font-size: 14px;width: 100%;padding-left: 10px;">
<div class="col-xs-6 col-sm-3" style="width:35%;">Stock Symbol</div>
<div class="col-xs-6 col-sm-3" style="width:25%;">P/E(ttm)</div>
<div class="col-xs-6 col-sm-3" style="width:20%;">P/S</div>
<div class="col-xs-6 col-sm-3" style="width:20%;">P/B</div>
</div>
</ons-page>
</ons-template>
<ons-template id="notes.html">
<ons-page ng-controller="portNotes">
<div class="row" style="height:20px;background-color: #144A88;color:white;font-size: 14px;width: 100%;padding-left: 20%;">
<div class="col-xs-6 col-sm-2" style="width:45%;">Stock Symbol</div>
<div class="col-xs-6 col-sm-2" style="width:55%;">User Notes</div>
</div>
</ons-page>
</ons-template>
</ons-page>

The problem is that you are trying to wrap everything inside an ons-page element and that's wrong. You can never wrap ons-template inside ons-page, just the opposite is fine.
To fix your app, just remove the last </ons-page> tag and add it immediately after </ons-tabbar>, you will have a main page like this:
<ons-page ng-controller="myPortfoliosController">
<ons-toolbar class="DCF">
<div class="left">
<ons-back-button style="color:white;"></ons-back-button>
</div>
<div class="center" style="font-size:22px;" >My Portfolios</div>
</ons-toolbar>
<ons-tabbar position="top">
<ons-tab page="price.html" active="true">Price</ons-tab>
<ons-tab page="ratios.html">Ratios</ons-tab>
<ons-tab page="notes.html" >Notes</ons-tab>
</ons-tabbar>
</ons-page>

Related

Uncaught (in promise) Error: "html" must be one wrapper element onsenui

I am trying to write a small Cordova App. Fortunatly found OnSenUI and now working on it. But I am facing this erorr:
Uncaught (in promise) Error: "html" must be one wrapper element.
at Object.util.createElement (util.js:147)
at page-loader.js:23
I searched for many solutions, but nothing worked for me.
My whole code:
<!DOCTYPE html>
<html>
<head>
<title>New App</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/onsenui.css" />
<link rel="stylesheet" href="css/onsen-css-components.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="js/onsenui.js"></script>
<script src="js/myJs.js"></script>
</head>
<body>
<ons-splitter>
<ons-splitter-side id="menu" side="left" width="220px" collapse swipeable>
<ons-page>
<ons-list>
<ons-list-item onclick="fn.load('home.html')" tappable> Home </ons-list-item>
<ons-list-item id="ons-list-fetch" onclick="fn.load('fetchPage.html');" tappable> Fetch Data </ons-list-item>
</ons-list>
</ons-page>
</ons-splitter-side>
<ons-splitter-content id="content" page="home.html"></ons-splitter-content>
</ons-splitter>
<ons-template id="home.html">
<ons-page id="helloworld-page">
<ons-toolbar>
<div class="left">
<ons-toolbar-button onclick="fn.open()">
<ons-icon icon="md-menu"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center"> Main </div>
</ons-toolbar>
<p style="text-align: center; opacity: 0.6; padding-top: 20px;"> Swipe right to open the menu! </p>
<!-- Inputs-->
<h2 style="text-align: center; opacity: 0.6;">Just H2</h2>
<div style="text-align: center; margin-top: 30px;">
<p>
<ons-input id="username" modifier="underbar" placeholder="Username" float></ons-input>
</p>
<p>
<ons-input id="password" modifier="underbar" type="password" placeholder="Password" float></ons-input>
</p>
<p style="margin-top: 30px;">
<ons-button id="btnClickMe">Click Me!</ons-button>
</p>
<section style="padding: 8px">
<ons-button modifier="quiet">Forgot Password</ons-button>
</section>
</div>
<!-- eof Inputs-->
<p style="text-align: center; font-size: 14px; opicity: 0.6"> All rights reserved </p>
</ons-page>
</ons-template>
<!-- fetchPage-->
<ons-template id="fetchPage.html">
<ons-page>
<ons-toolbar>
<div class="left">
<ons-toolbar-button onclick="fn.open()">
<ons-icon icon="md-menu"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center"> Fetch </div>
</ons-toolbar>
</ons-page>
<div id="divFtechHere">Fetched Data will be shown here</div>
</ons-template>
</body>
</html>
OMG Its too simple.
I was declaring <div id="divFtechHere"> outside <ons-page>
Wrong Code:
<!-- FetchPage-->
<ons-template id="fetchPage.html">
<ons-page>
<ons-toolbar>
<div class="left">
<ons-toolbar-button onclick="fn.open()">
<ons-icon icon="md-menu"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center"> Fetch </div>
</ons-toolbar>
</ons-page>
<div id="divFtechHere">Fetched Data will be shown here</div>
</ons-template>
Correct Code:
<ons-template id="fetchPage.html">
<ons-page>
<ons-toolbar>
<div class="left">
<ons-toolbar-button onclick="fn.open()">
<ons-icon icon="md-menu"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center"> Fetch </div>
</ons-toolbar>
<div id="divFtechHere">Fetched Data will be shown here</div>
</ons-page>
</ons-template>

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 - pushPage animation

I have a multiline toolbar. The code is like:
<ons-page id="prodotti">
<ons-toolbar fixed-style id="firstNav" class="first-line">
<div class="left">
<img src="dist/img/logo.png">
</div>
<div class="right">
<ons-toolbar-button onclick="myNav.pushPage('profilo.html')">
<ons-icon icon="ion-person" size="28px" fixed-width="false"></ons-icon>
</ons-toolbar-button>
<ons-toolbar-button onclick="myNav.pushPage('carrello.html')">
<ons-icon icon="ion-android-cart" size="28px" fixed-width="false"><span class="notification">1</span></ons-icon>
</ons-toolbar-button>
</div>
<div class="second-line navigation-bar" id="secondNav">
<div class="navigation-bar__left">
<span class="toolbar-button navigation-bar__line-height" onclick="menu.toggle()">
<i class="ion-navicon"
style="font-size:28px; vertical-align:-6px;"></i>
</span>
</div>
</div>
</ons-toolbar>
All my page have a toolbar like this one.
Now I have a problem. When I use pushPage with animation:slide the #secondNav doesn't seems to have animation. It will change after the end of the animation.
How I can implement the slide to this element?
Thank you!
There are some errors in your code. ons-toolbar accepts only div tags with class= left, center or right.
Your <div class="second-line navigation-bar" id="secondNav"> will never be displayed. To create a two line toolbar, just use two different toolbars.
In your code the navigator is missing, I added it on the first page. You also forgot to add the </ons-page> tag in the end.
Here you can find a working CodPen example, and here is your modified code:
<ons-template id="profilo.html">
<ons-page>
<ons-back-button>Go Back</ons-back-button>
</ons-page>
</ons-template>
<ons-page id="first">
<ons-navigator var="myNav">
<ons-toolbar fixed-style id="firstNav" class="first-line">
<div class="right">
<ons-toolbar-button onclick="myNav.pushPage('profilo.html')">
<ons-icon icon="ion-person" size="28px" fixed-width="false"></ons-icon>
</ons-toolbar-button>
<ons-toolbar-button onclick="myNav.pushPage('carrello.html')">
<ons-icon icon="ion-android-cart" size="28px" fixed-width="false"><span class="notification">1</span></ons-icon>
</ons-toolbar-button>
</div>
</ons-toolbar>
<div class="second-line navigation-bar" id="secondNav">
<div class="navigation-bar__left">
<span class="toolbar-button navigation-bar__line-height" onclick="menu.toggle()">
<i class="ion-navicon"
style="font-size:28px; vertical-align:-6px;"></i>
</span>
</div>
</div>
</ons-navigator>
</ons-page>

Onsen UI navigation not working after adding tabbar

I can't get the navigation to work with the tab bar. I have a list page, search page and details page. For some reason I can't get the list page to persist when navigating either. The details page is never shown even thought I am using app.navi.pushPage('detail.html'). Before adding the tab-bar everything worked fine. Any ideas on what I am doing wrong?
As well, I need to access the detail page from both the list and search pages.
<ons-navigator page="list.html" var="app.navi"></ons-navigator>
<ons-tabbar>
<ons-tab page="favourites.html" label="Favourites" icon="fa-heart"></ons-tab>
<ons-tab page="list.html" label="Near Me" icon="fa-map-marker" active="true"></ons-tab>
<ons-tab page="search.html" label="Search" icon="fa-search"></ons-tab>
</ons-tabbar>
<ons-template id="list.html">
<ons-page id="list-page">
<ons-toolbar>
<div class="center">Near Me</div>
</ons-toolbar>
<ons-list id="lst-estblshmnt"></ons-list>
</ons-page>
</ons-template>
<ons-template id="search.html">
<ons-page id="search-page">
<ons-toolbar>
<div class="center">Search</div>
</ons-toolbar>
<ons-row>
<ons-col>
<input id="srch" type="search" class="search-input">
</ons-col>
<ons-col width="75px" style="display: none">
<ons-button id="btn-cancel-search" modifier="quiet">Cancel</ons-button>
</ons-col>
</ons-row>
<ons-list id="lst-srch"></ons-list>
</ons-page>
</ons-template>
<ons-template id="detail.html">
<ons-page id="detail-page">
<ons-toolbar>
<div class="left"><ons-back-button>Back</ons-back-button></div>
<div class="right">
<ons-toolbar-button id="btn-fllw"><ons-icon icon="fa-heart-o"></ons-icon></ons-toolbar-button>
</div>
</ons-toolbar>
<ons-row>
<ons-col id="establishment-details">
<header>
<center class="item-title">Title</center>
</header>
<div class="item-details">
<ons-row>
<ons-col>
<p class="item-address"></p>
<p class="item-city"></p>
<p class="item-postal_code"></p>
</ons-col>
</ons-row>
</div>
</ons-col>
</ons-row>
</ons-list>
</ons-page>
</ons-template>
You cannot combine <ons-navigator> with <ons-tabbar>. If you use the tabbar element, you can switch pages using setActiveTab(index, [options]). I created a working sample using the template you provided and added a <ons-button> in the list.html template that changes the active page. For more info about the tabbar element, take a look here. Let me know if you need more help :)
<body>
<ons-tabbar var="tabbar">
<ons-tabbar-item
icon="home"
label="Home"
page="list.html"
active="true"></ons-tabbar-item>
<ons-tabbar-item
icon="comment"
label="Comments"
page="search.html"></ons-tabbar-item>
<ons-tabbar-item
icon="gear"
label="Settings"
page="detail.html"></ons-tabbar-item>
</ons-tabbar>
<ons-template id="list.html">
<ons-page id="list-page">
<ons-toolbar>
<div class="center">Near Me</div>
</ons-toolbar>
<ons-list id="lst-estblshmnt"></ons-list>
<ons-button id="btn-switch-search" ng-click="tabbar.setActiveTab(2)">Cancel</ons-button>
</ons-page>
</ons-template>
<ons-template id="search.html">
<ons-page id="search-page">
<ons-toolbar>
<div class="center">Search</div>
</ons-toolbar>
<ons-row>
<ons-col>
<input id="srch" type="search" class="search-input">
</ons-col>
<ons-col width="75px" style="display: none">
<ons-button id="btn-cancel-search" modifier="quiet">Cancel</ons-button>
</ons-col>
</ons-row>
<ons-list id="lst-srch"></ons-list>
</ons-page>
</ons-template>
<ons-template id="detail.html">
<ons-page id="detail-page">
<ons-toolbar>
<div class="left"><ons-back-button>Back</ons-back-button></div>
<div class="right">
<ons-toolbar-button id="btn-fllw"><ons-icon icon="fa-heart-o"></ons-icon></ons-toolbar-button>
</div>
</ons-toolbar>
<ons-row>
<ons-col id="establishment-details">
<header>
<center class="item-title">Title</center>
</header>
<div class="item-details">
<ons-row>
<ons-col>
<p class="item-address"></p>
<p class="item-city"></p>
<p class="item-postal_code"></p>
</ons-col>
</ons-row>
</div>
</ons-col>
</ons-row>
</ons-list>
</ons-page>
</ons-template>
</body>

Resources