ngMessages/angular validation not working - angularjs

I'm getting neither a value emitted by the template fragment nor functioning validation. My Jade template:
doctype html
html(lang='en', ng-app="Validate")
head
script(src='#{cdn_path}/angular.js/1.3.11/angular.js')
script(src='#{cdn_path}/angular.js/1.3.11/angular-messages.js')
script.
angular.module('Validate', ['ngMessages']);
body
.container
form(method="POST", action="/apply", name="myform", novalidate="")
pre myform.name.$error = {{ myform.name.$error }}
input.form-control(name="name", required="", pattern=".*[a-zA-Z].*", minlength=5)
ng-messages(for="myform.name.$error")
ng-message(when="required") Required!
ng-message(when="min") Too small!
input.btn(type='submit')
The resulting HTML: http://plnkr.co/edit/McyMXwW1b2Ae7kkwQ1sP
I'd like to avoid custom directives or much in the way of additional Javascript. What am I doing wrong?

This is happening because you didn't bind ng-model with the input :-)
<input name="name" ng-model="name" required="" pattern=".*[a-zA-Z].*" minlength="5" class="form-control">
<ng-messages for="myform.name.$error">
<ng-message when="minlength">Too small!</ng-message>
<ng-message when="required">Required!</ng-message>
Plunker:- http://plnkr.co/edit/kmNkfhdVOHQsstj6dpPT?p=preview

I just have the same issue and solved it. I want to share it so no one will waste an hour like me.
Please ensure the following:
1. Load the ngMessages module
<!-- Load Angular -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.0/angular.min.js"></script>
<!-- Load ngMessages -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.0/angular-messages.min.js"></script>
2. Inject ngMessages into our application module
angular.module( "app", [ "ngMessages" ] );
3. Try newer versions
For some reason, Doug Luce's code gets working just by changing versions to e.g., 4.11!

Related

Sendgrid handlebars #if statement in html checkbox

is it possible to do a replacement inside a HTML tag?
Template:
<input type="checkbox" disabled {{#if CompleteAndTrueConfirmation}}checked{{/if}} >
Test Data:
{
"CompleteAndTrueConfirmation": true
}
I get the error:
Unexpected character after / in tag. Expected >.
This template works but looks cumbersome:
{{#if CompleteAndTrueConfirmation}}
<input type="checkbox" disabled checked />
{{else}}
<input type="checkbox" disabled />
{{/if}}
No, it's not possible to use a Handlebars block like {{#if ... within an HTML start or end tag because it interferes with the HTML parsing in the SendGrid template editor. ☹
More info:
When I edit module HTML, paste your template, and save, I get an error:
When I edit the code again, I see the code has been modified because the editor tries to fix the HTML by making attributes out of the bits of Handlebars code:
It is possible to do substitution where the test data contains HTML (example), but that kind of defeats the purpose of using a template.

script not working in Angular JS

I have HTML file that is loaded by Angular JS in ng-view. This file contens code:
<script type="text/ng-template" id="searchbox.tpl.html">
<input type="text" placeholder="Search Box">
</script>
Why input fiels is not displayed in template? I see blank page.
This is Angular JS code:
$scope.searchbox = { template: 'searchbox.tpl.html', events: events };
Updated:
HTML file with include:
<div class="input-wrap">
<div ng-include="searchbox.template"></div>
</div>
HTML file searchbox.template:
<input type="text" ng-model="formData.address" ng-trim="true" ng-minlength="3" required>
You have added script that doesn't mean that it will render inner html on the page. After reading that script from Html, Since the type of script is type="text/ng-template" so angular internally put that script content inside a $templateCache service, And you can access that as template by using its id value as url in anywhere.
For getting shown it on the page you should use ng-include that will have src with searchbox.tpl.html
Markup
<div ng-include="searchbox.template"></div>
Working Plunkr

ionicframework setting up international-phone-number directive

Am learning ionic and I want to use this directive international-phone-number direcrive. I have linked the file on my index.html page
<script src="lib/international-phone-number/releases/international-phone-number.js"></script>
and in my view used one of the default examples from the link <input type="text" international-phone-number only-countries="pl, de, en, es" default-country="pl" preferred-countries="pl, de" ng-model="phone">
the directive is not working for me , what could I be doing wrong?

can i use angular js with kendoUi wrappers? if yes how?

I have 3 questions
can i use angular js with kendoUi wrappers? if yes how?
if i am using angular js and kendo-all.min.js on the same html tag let say that we are converting an input tag to auto-complete and at the same time we are binding it with ng-model then what possible affect they can produce in each other?
what actually angular-kendo is?
code for Point No-2
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/Kendo/kendo.all.min.js"></script>
<script src="~/Scripts/angular/angular.js"></script>
<script src="~/Scripts/angular/app.js"></script>*#
<script type="text/javascript">
$(document).ready(function () {
var data = ["akshay", "tiwari", "ranjit", "swain"];
$("#name").kendoAutoComplete({ dataSource: data });
})
</script>
<h2>KendoAngular</h2>
<div ng-app>
<input id="name" type ="text" ng-model="yourName"/>
<h2>{{yourName}}</h2>
</div>
There is a kendo project that you'll need to include: https://github.com/kendo-labs/angular-kendo
What will happen is that as the user types in say an autocomplete, the selection will be bound to an angular scope item. The "wrapper" is what makes all the bindings and allow angular to be updated.
From the github: angular-kendo is a directive for AngularJS that runs an element through Kendo UI declarative initialization, allowing you to take full advantage of Kendo UI within the context of an AngularJS Application.
You plunker is not including the angular adapter located at the link above.
Here are the instructions for its use: http://kendo-labs.github.io/angular-kendo/#/simple
var app = angular.module('your-angular-app', ["kendo.directives"]); // include directives
Add data-kendo and appropriate data- attributes.

Simple AngularJS running on JSFiddle

How do I make a jsfiddle out of the following code:
<html>
<head>
</head>
<body>
<div ng-app ng-controller="MainCtrl">
<ul>
<li ng-repeat="num in nums">
{{num}}
</li>
</ul>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.js"></script>
<script type="text/javascript" charset="utf-8">
function MainCtrl($scope) {
$scope.nums = ["1","2"];
}
</script>
</body>
</html>
My non working attempt: http://jsfiddle.net/zhon/3DHjg/ shows nothing and has errors.
You need to set some things up in jsFiddle for this to work.
First, on the left panel, under "Frameworks & Extensions", select "No wrap - in <body>".
Now, under "Fiddle Options", change "Body tag" to <body ng-app='myApp'>
In the JS panel, initiate your module:
var app = angular.module('myApp', []);
Check it out: http://jsfiddle.net/VSph2/1/
#pkozlowski.opensource has a nice blog post about how to use jsFiddle to write AngularJS sample programs.
You've defined your controller in a function scope that is not accessible to angular (angular is not yet loaded). In other words you are trying to call angular library's functions and helpers like below example before getting angular library loaded.
function onload(){
function MainCtrl(){}
}
To resolve this, switch your angular load type to be No wrap - in <body> like shown in screenshot.
here is a working example in jsfiddle
Click JAVASCRIPT button, choose angular version and place where u want include loaded script:
Then click HTML button and add ng-app in body tag. Its all:)
I am writing my answer for those who land on this page , I was used to use ng-module directive but in jsfiddle after half an hour I realized that ng-module is not allowed and you see no error , and when changed that ng-module to ng-app fiddle worked very well .I just wanted to share this .And no wrap (body) is required too.
<div ng-app="appX" ng-controller="appCtrl">
<p>{{greeting}}
</p>
</div>
var app=angular.module("appX",[]);
console.log(app);
app.controller("appCtrl",function($scope){
$scope.greeting="Hello World";
});
https://jsfiddle.net/cloudnine/trgrjwf1/7/
Since Angular 1.4.8 has been chosen by JSFiddle as the top option for Angular V1 in its JAVASCRIPT setting panel, more restriction applies: both ng-app and ng-controller should be declared in HTML to make it work.
Sample HTML:
<div ng-app="myApp" ng-controller="myCtrl">
<input type="text" ng-model="sample" placeholder="type something here...">
<span>{{sample}}</span>
</div>
Sample JS:
angular.module('myApp', [])
.controller('myCtrl', function($scope) {});
https://jsfiddle.net/y170uj84/
Also tested with the latest Angular 1.6.4, by setting as External Resource.
For little experiments in angular 5, you can use https://stackblitz.com/.
This site is used in angular documentation to run live demo. For example, https://stackblitz.com/angular/eybymjopmav

Resources