I want to create a text area where if i add some text and click on save, the text should be saved in localStorage. So if i open the text area again, i can see it still there.
HTML
<ion-view view-title="CWIN 2016 - Votre avis">
<ion-content>
<div class="list card user-infos-card">
<div class="item aw-dark-blue"> <h2 class="activity-name"></h2> Notes</div>
<textarea ng-model="note" rows="20" cols="50"></textarea>
<div class="item tabs tabs-secondary tabs-icon-left aw-dark-blue" ng-click="saveNote()" ng-model="note">Enregistrer vos notes</div>
<div ng-show="error">
<p class="form-error-message">Veuillez saisir des notes</p>
</div>
</div>
</ion-content>
</ion-view>
JS
angular.module('companion.noteBookController', ['LocalStorageModule'])
.controller('noteBookController', function ($scope, localStorageService){
$scope.note=localStorageService.get('note');
$scope.saveNote=function() {
localStorageService.set('note', $scope.note);
}
});
I don't underdstand the problem. Besides I don't have any errors.
Change this line
<div class="item tabs tabs-secondary tabs-icon-left aw-dark-blue" ng-click="saveNote(note)">Enregistrer vos notes</div>
and in js
angular.module('companion.noteBookController', ['$localStorage'])
.controller('noteBookController', function ($scope, $localStorage){
$scope.saveNote=function(note_val) {
console.log(note_val);
$localStorage.note = note_val;
}
});
if you want to get value then you can use this
var my_note = $localStorage.note;
Related
I am using angularjs and spring mvc for my application. At first I am displaying all the placements with one button Placed Candidates. I am doing ng-repeat for displaying all the placements.
Here is my html.
<div class="row" data-ng-repeat="placement in placements">
<div class="col-xs-12 col-sm-12 col-md-12">
<h5>{{placement.companyName}}</h5>
</div>
<div class="col-xs-12 col-sm-6 col-md-3">
<h6>{{placement.placementDate | date:'dd MMM yyyy'}}</h6>
Company Target (appox):10 Achieved:
</div>
<a href="javascript:void(0);" data-ng-
click="placedcandidatespopup(placement.placementId);">//here i can
get particular placementId but how to pass this id to
savePlacementStudents() method in controller.js???//
PlacedCandidates
</a>
</div>
I am calling one modal popup function. Here is controller.js
$scope.placedcandidatespopup = function()
{
AdminUsersService.getAllUsers().then(function(response)
{
$scope.allusers=response.data;
console.log($scope.allusers);
})
$(".placedcandidates").modal("show");
}
I am calling modal by name "placedcandidates".
Here is the modal
<div class="modal right fade placedcandidates" id="myModal1"
tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6" data-ng-
repeat="student in allusers">
<input id="{{student.studentId}}" type="checkbox" value="
{{student.studentId}}" data-ng-
checked="selection.indexOf(student.studentId) >-1"
data-ng-click="toggleSelection(student.studentId)"/>
<label for="{{student.studentId}}"></label>
{{student.firstName}}
</div>
</div>
</div>
<div class="modal-footer" style="position: fixed;">
<input type="button" value="Submit" class="btn" data-ng-
click="savePlacementStudents()">
</div>
</div>
</div>
</div>
After clicking on button popup modal will display with all Students with checkboxes placed beside them.Now I am able to save studentId into database.But I am not able to pass placementId for saving.
Here is my savePlacementStudents method in controller.js.
$scope.selectedStudents = {};
$scope.savePlacementStudents = function(selectedStudents)
{
selectedStudents.selectedList = $scope.selection;
AdminPlacementService.savePlacementStudents(selectedStudents).then
(function(response)
{
if(response.data=="success"){
$window.scrollTo(0,0);
$scope.selectedStudents = {};
$scope.getplacementdetails($scope.currentPageIndex);
$scope.successmessage="Student Selection Saved!;
$timeout(function() {
$scope.successmessage="";
$scope.closeplacedcandidatespopup();
}, 1500);
}
});
}
Can anyone tell how can I pass respective placementId to this saveStudents method() so that I can set that placementId for those students selected.
Here is the solution.
The placementId passed to function placedcandidatespopup can be saved as follows in function placedcandidatespopup
$scope.selectedPlacementId = placementId;
Now the same $scope will have access in Popup also as it is using same controller.js. And now you can use this $scope.selectedPlacementId anywhere in controller.js
So you don't need to pass placementId...!!
Hope that would help you..!!
$scope.placedcandidatespopup = function(id)
{
AdminUsersService.getAllUsers().then(function(response)
{
$scope.allusers=response.data;
console.log($scope.allusers);
})
$scope.inserted = {
placementId:id,
};
var modalInstance = $uibModal.open({
templateUrl: 'views/test/myModal1.html',
controller: 'TestCntrl',
size: "Modelwidth",
resolve: {
items: function () {
return $scope.inserted;
}
}
});
}
In model you have to access using items.placementId and when you savePlacementStudents() method send placementId as well with student info.
Update:
Using ng-include height is 0. I've provided a totally simplified example below. I need to know how to fix this and make it so the page says Hello.
<ion-view title="Page">
<ion-content padding="true" class="has-header">
<div ng-include="'templates/page30'"></div>
</ion-content>
</ion-view>
Where the templates/page30 file is
<p>Hello</p>
Original Post:
I need to figure out how to get my ng-include to be shown within an ng-switch. Currently the code does not work. Two things aren't happening as expected. The outer button is way small and the ng-included sub-forms are not showing as their height is 0. Please keep in mind I am using Ionic which means I do not have access to *.height().
NOTE: I'm only showing step 1 of the ng-switch otherwise this would be too bulky.
<ion-view title="Some Template" hide-nav-bar="true">
<ion-content padding="true" class="has-header">
<div ng-controller="someCtrl">
<ng-switch on="step">
<div ng-switch-when="1">
<div height-bind height-value="containerHeight">
<ng-include src="'templates/somepage.html'"></ng-include>
</div>
</div>
</ng-switch>
</div>
</ion-content>
</ion-view>
I have built a directive that looks like the following:
llApp.directive('heightBind', function() {
return {
scope: {
heightValue: '='
},
link: function($scope, $element) {
$scope.$watch(function() {
$scope.heightValue = $element.prop('offsetHeight');
});
}
}
});
The template called by ng-include is the following:
<ion-view title="Services" hide-nav-bar="true">
<ion-content padding="true" class="has-header">
<div class="page-header">
<h1>
<span>Lawncare</span>Services</h1>
</div>
<ul class="list">
<li class="item item-checkbox">
Mow Lawn
<label class="checkbox">
<input type="checkbox">
</label>
</li>
<li class="item item-checkbox">
Trim Plants
<label class="checkbox">
<input type="checkbox">
</label>
</li>
</ul>
</ion-content>
</ion-view>
One last thing. The controller someCtrl looks like the following: (actual controller reference is missing because I'm currently working within ionic creator)
function($scope, $stateParams) {
// Set the step initially to 1 every time this controllwer is instantiated.
// Usually on ng-switch button update the
// step value via the setStep function provided
$scope.step = 1;
$scope.setStep = function(step) {
$scope.step = step;
}
$scope.containerHeight = 0;
}
Some of the other things I've looked at to solve this. I have looked at:
http://stackoverflow.com/questions/25108780/height-of-container-with-ng-repeat-directive-is-zero
As well as this plunker:
Plunker
You are setting the height to 0 in the controller:
$scope.containerHeight = 0;
I have a button that when clicked makes a div disappear with ng-hide but i cant figure out how i can make the other div appear when i click that button. Right now my code is this:
<div class="col text-center"><button class="button b3" ng-click="goEsconder = !goEsconder">
Ver fotos
</button></div>
</div>
<div class="row" ng-hide="goEsconder">
<div class="col tipo"><p class="tip">Tipo de espaço:</p><p class="tip2">Escritório</p>
<p class="tip">Preço:</p><p class="tip2">{{detalhes[1]}}€/mês</p>
<div class="col tipo"><p class="tip">Condições:</p>
<p class="tip2">150 m2 de espaço
configurável</p>
</div>
My controller
.controller('perfilCtrl', ['$scope', '$stateParams', "detailService",// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams, detailService) {
$scope.detalhes=detailService.data;
$scope.goEsconder = false;
}])
And i want this div to show when the button is clicked and the other div hides
<div class="imagem">
<img ng-src="http://www.comoditamodulados.com.br/wp-content/uploads/2015/12/executivo_-300x300.jpg" class="img-responsive img-thumbnail">
</div>
<div class="imagem" ng-hide="!goEsconder">
<img ng-src="http://www.comoditamodulados.com.br/wp-content/uploads/2015/12/executivo_-300x300.jpg" class="img-responsive img-thumbnail">
</div>
Or as #Adwaenyth mentioned.
<div class="imagem" ng-show="goEsconder">
<img ng-src="http://www.comoditamodulados.com.br/wp-content/uploads/2015/12/executivo_-300x300.jpg" class="img-responsive img-thumbnail">
</div>
I've been stuck on a problem for 4 days. I use a plugin Autocomplete, a directive for AngularJS that uses a script in my html template.
I customized this to add a button that open a modal to add another city if autocomplete find nothing.
<ion-view title=""hide-nav-bar="true" hide-back-button="true" cache-view="false">
<script type="text/ng-template" id="/my-custom-template.html" >
<div class="angucomplete-holder" ng-class="{'angucomplete-dropdown-visible': showDropdown}">
<div class="angucomplete-row" ng-controller="ShareCtrl" ng-click="selectResult({title: searchStr, originalObject: { name: searchStr, custom: true }})" ng-mouseenter="hoverRow(results.length)" ng-class="{'angucomplete-selected-row': results.length == currentIndex}>
<div class="angucomplete-title" ng-click="openModal1()" ng-model="item.cat_id" style="text-align:center;"><i class="ion-plus-circled"></i> Ajouter un lieu</div>
</div>
</div>
</script>
<div class="item item-input" style="width:100%;overflow: visible;z-index:1000;">
<div angucomplete-alt id="members"
placeholder="Lieux"
pause="100"
selected-object="item.place"
remote-url="http://api.formcy.com/v1/search_place?search="
remote-url-data-field="data"
title-field="name"
initial-value="{{nomlieux}}"
template-url="/my-custom-template.html"
style="width:95%;"
/></div>
</div>
<label class="item item-input">
<textarea ngMaxlength="180" placeholder="Que vais-je faire cette semaine ?" ng-model="item.title" rows="3"></textarea>
</label>
<ion-toggle toggle-class="toggle-calm" ng-model="item.private" ng-true-value="1" ng-false-value="0">Name </ion-toggle>
</ion-view>
I use a ng-controller to open my modal and add another city but it does not return the scope updated on my controller ShareCtrl.
However, the function openModal1() is in this controller and work perfectly..
My controller
$scope.add = function(){
.....code.....
request.success(function(data, status, headers, config) {
$scope.status = "Votre lieux a été ajouté !";
$scope.item.place_id = data.place_id;
console.log($scope.item);
$scope.modalCtrl1.hide();
});
};
How I can force the $scope.item update without using a service?
If you want to avoid services, you could use events : $rootScope.$broadcast (or $emit) and $scope.$on.
I am using http.get and i need to reload a template after selecting a character so that my template gives the answer according to what I selected
The code of the template
<div class="container-fluid" ng-controller="CriterioCtrl">
<div id="result"></div>
<div>
Selected Items:
<div ng-repeat="id in selection">
{{id}}
</div>
</div>
<div ng-repeat-start="crit in data" class="row">
<h2 align="center">{{crit.name}}</h2>
<div ng-repeat="caracter in crit.characters" class="col-md-4">
<div type="checkbox" value="{{caracter.id}}" ng-checked="selection.indexOf(caracter.id) > -1" ng-click="clickSelection(caracter.id)">
<a href="#crit" class="thumbnail" ng-click="clickCriterios(caracter.id)">
<h4 align="center">{{caracter.name}}</h4>
<img ng-src="http://skaphandrus.com/{{caracter.image_url}}"/>
</a>
</div>
</div>
</div>
<div ng-repeat-end>
</div>
<!--<button class="btn" ng-click="toggle()">Toggle</button>
<p ng-show="visible">Hello World!</p> codigo de um botao -->
</div>
This code is for the selection
$scope.selection=[];
$scope.clickSelection = function clickSelection(caracterId) {
var idx = $scope.selection.indexOf(caracterId);
// is currently selected
if (idx > -1) {
$scope.selection.splice(idx, 1);
}
// is newly selected
else {
$scope.selection.push(caracterId);
}
var selectedId = $scope.selection;
console.log(selectedId);
// Check browser support
if (typeof(Storage) != "undefined") {
// Store
localStorage.setItem("idSelect", selectedId);
// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("idSelect");
}
};
This code is the http part in another controller
MyApp.controller('EspeciesCtrl', function ($scope, $http) {
$http({
url: 'someurl',
method: "post",
params: {module_id: localStorage.getItem("idMod"),"characters[]": [localStorage.getItem("idSelect")]}
})
.then(function(res){
$scope.data = res.data;
});
});
This is the code of the template that have to change after the selection
<div class="container-fluid" ng-controller="EspeciesCtrl">
<div class="row">
<div ng-repeat="esp in data" class="col-md-6">
<a href="#infEsp" class="thumbnail" ng-click="clickEspecie(esp.id)">
<h4 align="center">{{esp.name}}</h4>
<img ng-src="{{esp.image_src}}"/>
</a>
</div>
</div>
</div>
How can i do that?
edit 1
If I've correctly understood, you may need to use ng-show (https://docs.angularjs.org/api/ng/directive/ngShow) whose boolean value checks if the user selected anything and show the extra bit of code you need, instead of trying to have another http request.
Also, it seems like you are using $scope.data for both the esp and the crit, so you will end up with the errors.
You probably don't need to reload the template.
You may want to use the data in $scope.data inside the template in order to let Angular manage the update on the view. As soon as the $scope.data changes, the rendered HTML changes too.
I can't comment but it would be helpful if you could share the template you are using and be more specific in your request :)