angular not update file from app services - angularjs

Does anyone know why angular does not update the file in the browser? I try to use the incognito also same. the file recently I update not reflect on the browser. ng-repeat.
the HTML:
<body ng-app="cgpaCalculator">
<div class="card" ng-controller="cgpaCtrl">
[...]
<div class="row" ng-repeat="number in data.rows track by $index">
<div class="col-lg-5 mb-2">
<div class="form-label-group">
<input type="text" name="course_name" id="course_name" class="form-control" placeholder="Course Name [Optional]">
<label for="course_name">Course Name [Optional]</label>
</div>
</div>
<div class="col-lg-3 mb-2">
<div class="form-label-group">
<select class="form-control custom-select" ng-model="data.rows[$index].grade" ng-options="grade for grade in grades track by grade">
<option value="" disabled selected>Select Grade</option>
</select>
</div>
</div>
</div>
The Controller:
I don't know what i'm doing wrong.

Related

How to use required in ng-show?

I have a select box in that few values which is based on the selection i need to show the labels of the textbox.
ex: if you selected
the SE means I need to show the Location2 and Reporting To label box.
If you are selecting MANAger means need to show only Location2 label text
box only. And if you are selecting ADM/cluster, any one from this means need to be display only Location alone.
Js file
$scope.ChangeRole = function(id){
roleid=$scope.Role;
if(id=="2"){
// alert(id);
$scope.showreport =true;
$scope.showreportlocation=true;
$scope.showlocation = false;
}else if(id=="3"){
$scope.showreportlocation = true;
$scope.showreport = false;
$scope.showlocation = false;
}else{
$scope.showreport = false;
$scope.showreportlocation = false;
$scope.showlocation = true;
}
}
HTML file
<div class="col-lg-6">
<div class="form-group">
<label>Role<span style="color:red">*</span></label>
<div class="input-group role">
<select placeholder="Role" ng-model="Role" class="form-control pull-right" ng-change="ChangeRole(Role);" required ng-init="selectedType()" id="selectType"" name="role" required>
<option value="0">Role</option>
<option value="1">ADM</option>
<option value="2">SE</option>
<option value="3">MANA</option>
<option value="4">ClUSTER</option>
</select>
<div class="input-group-addon">
</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="form-group" ng-show="showlocation">
<label>Location<span style="color:red">*</span></label>
<div class="input-group location">
<select id="LocationInput" class="form-control" ng-model="LocationId" ng-options="location.Id as location.NameoftheLocation for location in locations" required>
<option id="OptionInput" value="">Location</option>
</select>
<div class="input-group-addon">
</div>
</div>
</div>
</div>
<div class="col-md-6" ng-show="showreportlocation">
<div class="form-group">
<label>Location2<span style="color:red">*</span></label>
<div class="input-group site">
<select data-placeholder="Location" style="width: 100%;" ui-select2="select2Options" class="form-group" multiple ng-model="selectedTags" required>
<option ng-repeat="tag in tags" value="{{tag.Id}}">{{tag.NameoftheLocation}}</option>
</select>
<div class="input-group-addon">
<i class="fa fa-map"></i>
</div>
</div>
</div>
</div>
<div class="col-lg-6" id="otherType" ng-show="showreport">
<div class="form-group">
<label>Reporting To<span style="color:red">*</span></label>
<div class="input-group">
<select class="form-control" id="reportingto" name="reportingto" ng-options="n.Id as n.Name for n in names" ng-model="ReportingTo" required>
<option value="">Reporting To</option>
</select>
<div class="input-group-addon">
</div>
</div>
</div>
</div>
Here I have given the required option for all but which is not allowing me to save because required is present.
Using ng-show for particular selection I hide that label, but while saving html will check that field also, which is wrong please let me know that how to do.
Please some make the fiddle and let me know,
Use ng-required instead and only require it when it is shown.
I also tested Casey's suggestion of using ng-if instead of ng-show and that works as well. https://plnkr.co/edit/eeKvz5zRFeuLSF6fDbuy?p=preview

ng-model not updating AngularJS

So i have this html. The issues is that is changing the model(filter) when i select one of those that i have create in a static way but the dynamic ones does not trigger the change of the value. Any ideas?
Thanks.
<div class="row">
<div class="col-xs-6">
<h3>Group 1</h3>
<hr>
<div class="checkbox">
<input type="radio" name="filterGroup" ng-model="filter" ng-value="5"><label>5</label>
</div>
<div class="checkbox">
<input type="radio" name="filterGroup" ng-model="filter" ng-value="4'"><label>4</label>
</div>
</div>
<div class="col-xs-6">
<h3>Group 2</h3>
<hr>
<div class="checkbox">
<input type="radio" name="filterGroup" ng-model="filter" ng-value="3"><label>3</label>
</div>
<div class="checkbox">
<input type="radio" name="filterGroup" ng-model="filter" ng-value="2'"><label>2</label>
</div>
<div class="checkbox">
<input type="radio" name="filterGroup" ng-model="filter" ng-value="1"><label>1</label>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<h3>DinamicItems</h3>
<hr>
<div class="checkbox" ng-repeat="item in items">
<input type="radio" name="filterGroup" ng-model="filter" ng-value="'{{item.value}}'"><label>{{item.text}}</label>
</div>
</div>
</div>
What Charlie is saying is, your model of tag is a primitive one. Each instance of ng-repeat creates it's own scope. Therefore, your models, although named 'tag', are not in fact the same.
To remedy, you should make your model something like vm.tags (vm = view model.)
A few things to read up on, and learn more:
Controller As: https://johnpapa.net/angularjss-controller-as-and-the-vm-variable/
ng-repeat: https://docs.angularjs.org/api/ng/directive/ngRepeat
Understanding Scopes https://github.com/angular/angular.js/wiki/Understanding-Scopes (When I was getting started with Angular, I had to read through this a few times, and still do on occasion)

Review form using angular js

I am trying to build an online store for my project, and i wish i could add a review form in one of my pages, i am getting a problem with inserting the input value into the array ! here is my files
details.html
<div class="col-sm-12">
<div class="row">
<div ng-controller="reviewController">
<h3 class="pdt-title">Review</h3><hr>
<div class="alert alert-danger" ng-if="reviews.length == 0">
No reviews yet, be the first to review this Product!
</div><br>
<div class="col-sm-12" ng-repeat="review in reviews" >
<blockquote class="row">
<h3 class="pdt-title col-sm-6">{{review.username}}</h3>
<h3 class="pdt-title col-sm-6">{{review.star}}</h3>
<h5 class="col-sm-12"><small><i>{{review.email}}</i></small></h5>
<p class="col-sm-12">{{review.message}}</p>
</blockquote>
</div>
<form class="form-inline form-group">
<div class="input-group">
<span class="input-group-addon">Name</span>
<input class="form-control" type="text" ng-model="username"></input>
<span class="input-group-addon">E-mail</span>
<input class="form-control" type="email" ng-model="email"></input>
<span class="input-group-addon">Star</span>
<select class="form-control" ng-model="star">
<option name="oneStar" value="1 star">1 Star</option>
<option name="twoStar" value="2 star">2 Star</option>
<option name="threeStar" value="3 star">3 Star</option>
<option name="fourStar" value="4 star">4 Star</option>
<option name="fiveStar" value="5 star">5 Star</option>
</select>
</div>
</form>
<textarea class="form-control" rows="5" ng-model="message"></textarea><br>
<input type="submit" class="btn btn-block btn-success" ng-submit="addReview()" value="Submit review"></input>
</div>
</div>
</div>
</div>
</div>
and here is my controller
app.js
app.controller('reviewController',function($scope){
$scope.reviews=[];
$scope.addReview=function(){
$scope.reviews.push({
name:$scope.username,
email:$scope.email,
star:$scope.star,
message:$scope.message
});
};
});
it would be great if someone explains the comments staying on the page even when the page is refreshed, usually the comments get lost when the page is refreshed.
As said in the comments, you should load your comments from somewhere. A service should do the job.
But your problem was with your ng-submit button. Didn't inspect in deep but I changed to ng-click and it worked. Also, be sure to always place your "fields" inside an object and not directly on the $scope.
//Set the models inside an object
$scope.review = {};
And then
<input class="form-control" type="text" ng-model="review.username" />
Here's an updated:
Fiddle
As an extra tip, if you haven't check this awesome guide yet you should save some time and read through it:
angular-styleguide
It contains a compilation of angular best practices written by John Papa.

Show/Hide divs depend on dropdown select in AngularJS

I am trying to show a div depending on what is selected from the drop down list. For example, if a user selects 'Cash' from the list show Cash div or if the user select 'Check' from the list show Check div
I have put together sample but its incomplete and needs to wire-up
http://jsfiddle.net/abuhamzah/nq1eyj1v/
Also when the user change the selection I would also like to clear the previous selection so when the user goes back to the previous selection they should not see.
<div ng-controller="MyCtrl">
<div class="col-xs-12">
<label class="col-xs-6 control-label">Type:</label>
<div class="col-xs-6">
<select name="type" ng-model="payment.type" ng-dropdown required ng-change="changeme()" >
<option ng-option value="Cash">Cash</option>
<option ng-option value="Check">Check</option>
<option ng-option value="Money Order">Money Order</option>
</select>
</div>
</div>
<div class="col-xs-12" id="cash">
<div >
<label class="col-xs-6 control-label">Cash :</label>
<div class="col-xs-6">
<input type="number" class="form-control" ng-model="payment.cash" />
</div>
</div>
</div>
<div class="col-xs-12" id="check">
<div >
<label class="col-xs-6 control-label">check :</label>
<div class="col-xs-6">
<input type="number" class="form-control" ng-model="payment.check" />
</div>
</div>
</div>
<div class="col-xs-12" id="money_order">
<div >
<label class="col-xs-6 control-label">money_order :</label>
<div class="col-xs-6">
<input type="number" class="form-control" ng-model="payment.money_order" />
</div>
</div>
</div>
</div>
//controller:
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.changeme = function() {
alert('here');
}
}
you didnt initialize as the angular app coz u missed the ng-app directive first
and this is the solution using ng-if
DEMO
<div ng-app="myApp" ng-controller="MyCtrl"> // initialize as a angular app
<div class="col-xs-12" id="cash" ng-if="payment.type == 'Cash'"> // this div will show if the value of `payment.type` model equals to `cash`. and so on.

How to create contact form in joomla 3

I'm Trying to create custom contact form in Joomla 3 , the reason is I didn't found such big contact form.
Can somebody tell me how to do it ?
html:
<div class="col-lg-12">
<form role="form" method="POST" style="margin-top: 2.7em;" action="">
<div class="row">
<div class="form-group col-lg-4">
<label for="input1">Name</label>
<input type="text" name="contact_name" class="form-control" id="input1">
</div>
<div class="form-group col-lg-4">
<label for="input2">Mail</label>
<input type="email" name="contact_email" class="form-control" id="input2">
</div>
<div class="form-group col-lg-4">
<label for="input3">Phone</label>
<input type="phone" name="contact_phone" class="form-control" id="input3">
</div>
<div class="form-group col-lg-4">
<label for="input1">Dropdown</label>
<select class="form-control" name="bud">
<option value="a">parterowy</option>
<option value="b">piętrowy</option>
<option value="c">bliźniak</option>
<option value="c">mieszkalny</option>
<option value="c">niemieszkalny</option>
</select>
</div>
<div class="form-group col-lg-4">
<label for="input2">Size</label>
<input type="email" name="contact_email" class="form-control" id="input2">
</div>
<div class="form-group col-lg-4">
<label for="input3">Garage</label>
<select class="form-control" name="garaz">
<option value="a">wolnostojący</option>
<option value="b">w budynku</option>
<option value="c">jednostanowiskowy</option>
<option value="c">wielostanowiskowy</option>
</select>
</div>
<div class="clearfix"></div>
<div class="form-group col-lg-12">
<label for="input4">Msg</label>
<textarea name="contact_message" class="form-control" rows="6"id="input4"></textarea>
</div>
<div class="form-group col-lg-12">
<input type="hidden" name="save" value="contact">
<button type="submit" class="btn btn-default">Send</button>
</div>
</div>
</form>
</div>
Fiddle to html
I read that i need to create custom component or rebuild other, which one is better option ?
You could use Chronoforms component to create virtually any form you like.
If you need some very special custom output, you can first use the included form bulider to set up the closest approximation and modify it as you like.
As you have already made the html part, the easier way is to implement your code in a custom module or for a more advanced result in a custom component.
The official joomla way for adding extra fields to contact form is by creting a custom plugin.
If you want a commercial solution (component) I would suggest you to use breezingforms.
Hope this helps

Resources