I am trying to implement the $ionicPopover but for some reason it won't work in my project. But when I run it in Codepen it does. Anybody can tell me why?
My html code:
<div ng-controller="SettingsCtrl">
<ion-view view-title="Instellingen">
<ion-content >
<div class="padding">
<p class="textContact">Title</p>
<p class="textContact">Title 2</p>
</div>
<div>
<p class="textContact" ng-click="openPopover($event)">Taal</p>
</div>
</ion-content>
<script id="popover.html" type="text/ng-template">
<ion-popover-view>
<ion-content>
<div class="list">
<a class="item">
Lorem Ipsum
</a>
</div>
</ion-content>
</ion-popover-view>
</script>
</ion-view>
</div>
My controller code:
angular.module('ChemicarSettings.controllers', [])
.controller('SettingsCtrl', function($scope, $ionicPopover){
$scope.openPopover = function ($event) {
$ionicPopover.fromTemplateUrl('popover.html', {
scope: $scope
}).then(function(popover) {
$scope.popover = popover;
$scope.popover.show($event);
});
};
})
How about checking the app.js? Did you add the ChemicarSettings.controllers to the angular.module line in the app.js? For instance..
angular.module('ChemicarSettings', ['ionic','ChemicarSettings.controllers'])
Also add "ionic" in the first line of the ChemicarSettings.controllers:
angular.module('ChemicarSettings.controllers', ['ionic'])
Related
I want to generate dynamic modals using Ionic, and have created a controller that dynamically has the id of the ng-repeat item which is linked to a unique modal. The modal is under a under the ion-item
Controller
$scope.showModal = function(id){
$ionicModal.fromTemplateUrl(id+'-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
window.modal.show();
$scope.openModal = function() {
$scope.modal.show();
};
$scope.closeModal = function() {
$scope.modal.hide();
};
}
View
< ion-item collection-repeat="hist in history" ng-show="history.length" style="background:none;border:none">
<div class="list card" ng-click="showModal(id)">
<div class="item ">
<div class="row" >
<div class="col col-25" > <span style="float:left;padding-top:0.4em"><i class="ion-clock largericon"></i></span> </div>
<div class="col col-75" align="left">
<div style="float:left">
<div style="font-size:2em">{{hist.session_time}} </div>
<div style="color:#999"> {{hist.human_date}}</div>
</div>
</div>
</div>
</div>
</div>
<script id="1-modal.html" type="text/ng-template">
<ion-modal-view style="background:#24112B">
<ion-header-bar class="bar bar-header bar-royal">
<h1 class="title">Session Started... </h1>
<button class="button button-clear button-primary" ng-click="modal.hide()"><i class="ion-close-round"></i></button>
</ion-header-bar>
<ion-content class="padding">
<div style="padding-top:1.3em;padding-bottom:1.3em">
<div class="row" align="center" >
<div class="col col-100" align="center">Start by keeping your repetitions to the beat...</div>
</div>
</div>
</ion-content>
</ion-modal-view>
</script>
</ion-item>
See it working: https://plnkr.co/edit/UcoU4i?p=preview
$scope.showModal = function(id){
$ionicModal.fromTemplateUrl(id+'-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
$scope.modal.show(); // show modal after it was loaded
});
}
EDIT: Also make sure ng-click="showModal(id)" you pass some actual id...
I have a view with one list item. After user clicked on this item, the modal form show. When user change value and close modal, the item-not not updating.
View:
<ion-view ng-controller="settingsController">
<ion-content>
<div class="list">
<ion-item class="item-icon-left" ng-click="openLanguageModal()">
<i class="icon ion-chatboxes"></i>
{{'Language'| translate}}
<span class="item-note">
<div ng-bind="choice"></div>
</span>
</ion-item>
</div>
</ion-content>
<script id="language-modal.html" type="text/ng-template">
<div class="modal">
<ion-header-bar>
<!-- <button class="button button-full button-dark" ng-click="closeLanguageModal()">{{'Done' | translate}}</button> -->
<button class="button button-clear button-positive pull-right" ng-click="closeLanguageModal()">
{{'Done' | translate}}
</button>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-radio ng-model="choice" ng-value="'en'"> English </ion-radio>
<ion-radio ng-model="choice" ng-value="'ru'"> Русский </ion-radio>
</ion-list>
</ion-content>
</div>
</script>
</ion-view>
Controller:
app.controller('settingsController', function($scope, $ionicModal) {
$ionicModal.fromTemplateUrl('language-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.languageModal = modal;
})
$scope.choice = "en";
$scope.openLanguageModal = function() {
$scope.languageModal.show();
}
$scope.closeLanguageModal = function() {
$scope.languageModal.hide();
};
$scope.$on('$destroy', function() {
$scope.languageModal.remove();
});
});
I dont understand why the ng-bind didnt updates, help please
Try to use:
$scope.model.choice = "en";
in a main Controller (so that all other view controllers could inheritate this info).
and in all view (settings and language-modal) modify to:
ng-model="model.choice"
due to prototypal inheritance...
Here it is a working demo: http://codepen.io/beaver71/pen/XXaROB
I am just trying to follow this example.
Here is my code:
angular.module('starter.controllers', [])
.controller('PaymentListCtrl', function ($scope,$ionicModal,$timeout) {
$scope.firstName = "John";
$scope.productItems = [
{
name: 'Product 1',
price: '$50.00'
},
{
name: 'Product 2',
price: '$45.00'
}
];
$scope.message = 'Everyone come and see how good I look!';
$ionicModal.fromTemplateUrl('modal_transaction_code.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal
})
$scope.openModal = function() {
$scope.modal.show()
}
$scope.closeModal = function() {
$scope.modal.hide();
};
$scope.$on('$destroy', function() {
$scope.modal.remove();
});
});
Modal Form
<label class="item item-radio" id="hashtagRadio" ng-controller="PaymentListCtrl">
<input type="radio" name="settings-group" value="search">
<div class="item-content">
<span class="ion-pound"></span> <span id="hashtagInput">MODAL FORM</span>
</div>
<i class="radio-icon ion-checkmark"></i>
</label>
its simple..!
<body ng-app="starter" ng-controller="PaymentListCtrl">
<ion-pane>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-content>
<button
class="button button-full button-assertive"
style = "margin-top: 0px;"
ng-click = "openModal()">
Open modal
</button>
</ion-content>
</ion-pane>
</body>
</html>
<script id="modal_transaction_code.html" type="text/ng-template">
<ion-modal-view class="mdx-modal" >
<ion-header-bar class="dark">
<div class="title text-center">Hola</div>
<button class="button button-clear ion-close" ng-click="closeModal()"></button>
</ion-header-bar>
<ion-view>
<ion-content class=" content-stable" >
<label class="item item-radio" >
<input type="radio" name="settings-group" value="search">
<div class="item-content">
<span class="ion-pound"></span> <span >MODAL FORM</span>
</div>
<i class="radio-icon ion-checkmark"></i>
</label>
</ion-content>
</ion-view>
</ion-modal-view>
</script>
make sure, above code remains in same .html file
and PaymentListCtrl controller code is right..!
hope u make it..!
My ngClick call is not working. It throws no error nor do the function I've declared in $scope. Everuthing else seems to work just fine. My code is as follows:
ng-app:
var app = angular.module('dilemas', [
'ngRoute',
'dilemas.controllers',
'dilemas.services'
]);
The controller:
_module.controller('controllerName', ['api', '$scope', function(api, $scope) {
$scope.gotoNext = function(){ console.log("I'm here ;)") };
}]);
The view:
<div id="myID" ng-controller="controllerName">
<div class="ct-full">
<div class="ct-center">
<h1 class="pergunta">Question?</h1>
</div>
</div>
<div ng-include="'include/footer.html'"></div>
</div>
And finally the footer include:
<div id="footer" class="ct-full">
<div class="ct-full">
<div class="ct-center">
<div class="btn btnNext spriteBase" ng-click="gotoNext()">Next ></div>
</div>
</div>
</div>
You can't call gotoNext method because ng-include creates a new child scope.
You could use $parent.gotoNext() in ng-click.
<div class="btn btnNext spriteBase" ng-click="$parent.gotoNext()">Next ></div>
I'm trying to call the function on clicking on List item using Angular JS. But, its not getting called. But, its working for a button.
HTML
<div ng-controller="Ctrl">
<button class="btn" ng-click="changeLanguage('en')" translate="BUTTON_LANG_EN" class="ng-scope">english</button>
<button class="btn" ng-click="changeLanguage('de')" translate="BUTTON_LANG_DE" class="ng-scope">espanol</button>
</div>
<div class="nav">
<div>Select Language</div>
<ul>
<li><img src="img/16.png">English</li>
<li><img src="img/13.png"><a href="" ng-click="changeLanguage('de')" >Español</a></li>
</ul>
</div>
JavaScript
var app = angular.module('at', ['pascalprecht.translate']);
app.config(function ($translateProvider) {
$translateProvider.translations('en', { // Translate w.r.t English.
BUTTON_LANG_EN: 'English',
BUTTON_LANG_DE: 'Español',
Charcoal:'Charcoal Hoodie',
CrestCrewNeck:'Crest Crew Neck',
GeoLoveCrewNeck:'Geo Love Crew Neck',
NavyHoodie:'Navy Hoodie',
BrainiacTShirt:'Brainiac T Shirt',
CrestTShirt:'Crest T Shirt',
GeometricTShirt:'Geometric T Shirt',
SellMoreManTShirt:'Sell More Man T Shirt'
});
$translateProvider.translations('de', { // Translate w.r.t Spanish.
BUTTON_LANG_EN: 'Englisch',
BUTTON_LANG_DE: 'Español',
Charcoal: 'Hoodie carbón',
CrestCrewNeck:'Cresta del cuello de equipo',
GeoLoveCrewNeck:'Geo amor del cuello de equipo',
NavyHoodie:'Hoodie Navy',
BrainiacTShirt:'Brainiac T Shirt',
CrestTShirt:'Cresta T Shirt',
GeometricTShirt:'Geométrico T Shirt',
SellMoreManTShirt:'Vender más hombre T Shirt'
});
$translateProvider.preferredLanguage('en'); // On page load with English content.
});
app.controller('Ctrl', function ($scope, $translate) { // Inject $translate.
$scope.changeLanguage = function (key) {
$translate.uses(key); // Based on the Key.
};
});
Can you please check the code?
Problem is that Your list is not under controller
Your code
<div ng-controller="Ctrl">
<!--Your controller scope-->
</div>
<div class="nav">
<ul>
<li><img src="img/16.png">English</li>
<li><img src="img/13.png"><a href="" ng-click="changeLanguage('de')" >Español</a></li>
</ul>
</div>
Change it to, Bring nav div under controller
<div ng-controller="Ctrl">
<div>
<button class="btn" ng-click="changeLanguage('en')" translate="BUTTON_LANG_EN" class="ng-scope">english</button>
<button class="btn" ng-click="changeLanguage('de')" translate="BUTTON_LANG_DE" class="ng-scope">espanol</button>
</div>
<div class="nav">
<div>Select Language</div>
<ul>
<li><img src="img/16.png">English</li>
<li><img src="img/13.png"><a href="" ng-click="changeLanguage('de')" >Español</a></li>
</ul>
</div>
</div>