I'm trying to figure out how ng-keyup works and I found some tutorials and sources, but when I tried to make one myself it doesn't work. You can see my codepen example here, http://codepen.io/alucardu/pen/XbOWRP and this is a JSfiddle example I tried to recreate http://jsfiddle.net/r74a5m25/.
html
<div ng-app>
<div ng-controller="exampleCtrl">
<input ng-model="test" ng-keyup="search()" />
<br/>
<span>{{test}}</span>
</div>
</div>
javascript
function exampleCtrl($scope) {
$scope.search = function() {
alert('test');
};
}
This problem come from the version of your angular. The earliest doc I can find in angularjs about ng-keyup is on the version 1.1.2. And you are using the previous version, 1.1.1.
Personnaly, I try with 1.2.0 in your codepen and it works
: https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js
This version is use in the JSFiddle that's why it works fine there.
You didn't use ng-keyup in the example. You have to bind your function to your input, just like you do with ng-model:
<input ng-model="test" ng-keyup="search()"/>
You need to try down with latest version of angularjs. The formats should be maintained.
<div ng-app="testApp">
<div ng-controller="exampleCtrl">
<input ng-model="test" ng-keyup="search()" />
<br/>
<span>{{test}}</span>
</div>
</div>
Javascript
myApp = angular.module("testApp",[]);
myApp.controller("exampleCtrl",function($scope){
$scope.search=function(){
alert("test");
}
});
Related
I am binding the angular java script expression to bind the simple value i have written in controller function.
here is my webpage code that is created using master page,
<div class="dashboard-content-wrap auto-padding" ng-app="myModule" ng-controller="myController">
<div>
{{employee.name}}--{{employee.country}}--{{1+2}}
</div>`enter code here`
and given below is js file code,
var myApp = angular.module("myModule", [])
.controller("myController", function ($scope) {
var employee={name:"john",country:"US"};
$scope.employee = employee;
});
i am not able to bind this value in my web page please help?
I dont see any problem with your code except a missing div tag.
<body>
<div class="dashboard-content-wrap auto-padding" ng-app="myModule" ng-controller="myController">
<div>
{{1+2}}
{{employee.name}}--{{employee.country}}--{{1+2}}
</div>
</div>
</body>
Please see if this fiddle helps you.
I have created a test project with Meteor which uses Masonry. I added the package mrt:jquery-masonry(or isotope:isotope), and it works well at the beginning. However, the problem comes now.
Basically, I want to implement the feature that when user clicks the button, the page will be added one more div. Below is my code:
main.html
<body>
<div class="container">
{{> masonryContent}}
</div>
<script>
(function($){
var $container = $('.masonry-container');
$container.masonry({
columnWidth: 300,
gutterWidth: 50,
itemSelector: '.masonry-item'
})
}(jQuery));
</script>
</body>
style.css
.masonry-item {
width: 300px;
}
masonry-content.html
<template name="masonryContent">
<div class="masonry-container">
<div class="masonry-item">
<p>blabla...</p>
<p>
Button
</p>
</div>
<div class="masonry-item">
<p>test...</p>
</div>
<div class="masonry-item">
<p>another test...</p>
</div>
{{#if showItem}}
<div class="masonry-item">
<p>new added item...</p>
</div>
{{/if}}
</div>
</template>
masonry-content.js
Template.masonryContent.events({
"click #click-me": function(e) {
e.preventDefault();
Session.set('show_me', true);
}
});
Template.masonryContent.helpers({
showItem: function() {
return !!Session.get('show_me');
}
});
The problem is when I click the button, the new div was created; however, it wasn't placed by following Masonry rules. The new created item just overlapped to the first item, but I expect it performs the way to append to the last item.
I would appreciate if anyone could help me on this.
Thanks in advance!
As meteor does partial rendering the element needs to be there in the DOM for masonry to work. So there are two ways of getting over the problem
1) Hide or unhide the element when the button click happens
Or
2) re-render the DOM
You can use the chrome dev tools to see what DOM elements are touched/refreshed (Green color).
There is a typo in masonry in the template name insertion.
Check the package state, many mrt packages are not well supported anymore.
I'm trying hard to get a date picker on my meteor application. I tested lot of packages found by googling, but none seems to work, or, probably, I'm doing it wrong. Can someone tell me clearly how to add a date picker?
Thanks a lot!
I would use the bootstrap 3 package and the bootstrap 3 date time picker package:
$ meteor add twbs:bootstrap
$ meteor add tsega:bootstrap3-datetimepicker
Then, simply add the form in your HTML file:
<template name="myTemplate">
<form>
<div class="form-group">
<label for="myInput">Input name</label>
<div class="input-group datetimepicker">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input name="idInput" id="idInput" class="set-due-date form-control" type="text"/>
</div>
</div>
</form>
</template>
And in your corresponding JavaScript file, you have to initialize your date time picker:
Template.myTemplate.rendered = function(){
$('.datetimepicker').datetimepicker();
};
And if you have different date input in your page (for example):
Template.myTemplate.rendered = function(){
$('.datetimepicker').each(function(){
$(this).datetimepicker();
});
}
Finally, I invite you to read the Documentation if you need more options (like date format etc).
Hope it will help you!
I use the one from eonasdon (Bootstrap required) and you get get it prepackaged by doing this:
meteor add hujhax:bootstrap3-datetimepicker
I have these packages added
twbs:bootstrap
jquery
rajit:bootstrap3-datepicker
and used this in the template
<div class="box-body no-padding">
<!--The calendar -->
<div id="calendar" style="width: 100%"></div>
</div><!-- /.box-body -->
and added helper below
Template.myCalendar.rendered = function() {
$('#calendar').datepicker();
}
I have a layout like this. I am using passsy extension for angular masonry.
<masonry column-width="200">
<div class="masonry-brick" ng-repeat="data in comments">
<div ng-switch on="data.type">
<div ng-switch-when="hoots">
<article class="hoot_main">
//content goes here
//hoot_main is the main class for this div layout
</article>
</div>
</div>
</div>
<div ng-switch on="data.type">
<div ng-switch-when="article">
<article class="hoot_main">
//content goes here
//hoot_main is the main class for this div layout
</article>
</div>
</div>
<div ng-switch on="data.type">
<div ng-switch-when="story">
<article class="hoot_main">
//content goes here
//hoot_main is the main class for this div layout
</article>
</div>
</div>
</div>
</masonry>
Browser is getting hanged whenever I use it. Debugging script with tools says element.masonry is not a function.
Any help would be appreciated!
Hmm, at the moment I work from my laptop at home and I can't get passy's version running too and can not put my finger on the issue. But this is what I can offer you for now:
I made a very simple directive based on things I've read somewhere:
app.directive('masonry', function() {
return {
restrict: 'AC',
controller: function($scope) {
return $scope.$watch(function(e) {
$scope.masonry.reloadItems();
return $scope.masonry.layout();
});
},
link: function(scope, elem, attrs) {
var container=elem[0];
var options='';
return scope.masonry = new Masonry(container,options);
}
};
As you can see it does not have a any options by now. When i'm at work on monday i will have a look at my sources on a proper dual screen display and provide you with a better version.
My wife is starting to giving me the looks and I need to put the laptop away now. :-\
You can see in this plunker that it kinda works now. Maybe this can help you. In the meantime can you add some of your json data to your question? Have a nice weekend for now!
In order to get Passy's angularjs directive working you must include all the files as listed per the index file
I had this error, fixed it by including the original Masonry code. I was also thinking this was a pure angular port.
I try to use parsley for validation with meteor following this question: Using Parsley.js with Meteor using HTML Code
I run meteor 0.6.6.3 on Ubuntu 13.10, added package jquery and added parsley 1.1.7 from atmosphere (https://atmosphere.meteor.com/package/parsleyjs) with meteorite.
I also tested with the current version 1.2.2 of parsley from client/lib (after removing parsleyjs with mrt).
Knowing that I can't use the HTML markup for validation I created a template like this
<template name="new_customer">
<form id="new_customer_form">
<div class="newCustomer">
<div class="lookupcell">
<input type="text" size="1"
name="new-customer-name"
id="new-customer-name"
class="new-customer-name"
placeholder="neue Firma/Person"
parsley-notblank="true" />
</div>
<div class="lookupcell">
<input type="text" size="1" id="new-customer-email"
name="new-customer-email"
id="new-customer-email"
parsley-type="email"
parsley-trigger="keyup"
class="new-customer-email" placeholder="Email" />
</div>
</div>
<div style="text-align: right;">
<button type="submit">Add</button>
</div>
</form>
</template>
and the following javascript for setup
Template.new_customer.rendered = function () {
console.log("rendered new_customer");
$new_customer_form = $( '#new_customer_form' );
if (! $new_customer_form) {
console.log("form not found.");
return;
}
$new_customer_form.parsley();
$new_customer_form.parsley( 'addItem', '#new_customer_name' );
};
meteor crashes on rendering at the last line when I try to add the field #new_customer_name with the following stacktrace
[09:44:11.969] "Exception from Deps afterFlush function: ParsleyForm.prototype.addItem#http://localhost:3000/packages/parsleyjs.js?ed9f338553f590de7edeb7b3e5ca8cb568f2e74d:1152
bind#http://localhost:3000/packages/parsleyjs.js?ed9f338553f590de7edeb7b3e5ca8cb568f2e74d:1295
$.fn.parsley#http://localhost:3000/packages/parsleyjs.js?ed9f338553f590de7edeb7b3e5ca8cb568f2e74d:1305
Template.new_customer.rendered#http://localhost:3000/client/X4Lizenzen.js?7d0644137e559b675577266ad6e2f78f087b3453:151
Template.__define__/partial/html</html<.rendered#http://localhost:3000/packages/templating.js?5944cd5e16b26fbf83959a0fe92d7754029a624d:181
scheduleOnscreenSetup/</<#http://localhost:3000/packages/spark.js?3a050592ceb34d6c585c70f1df11e353610be0ab:443
_.forEach#http://localhost:3000/packages/underscore.js?13ab483e8a3c795d9991577e65e811cd0b827997:130
scheduleOnscreenSetup/<#http://localhost:3000/packages/spark.js?3a050592ceb34d6c585c70f1df11e353610be0ab:441
.flush#http://localhost:3000/packages/deps.js?5ac28feec1f3e0539889ecde598dd9d01e408b41:265
"
The stack does not tell me what the actual problem is (or rather I don't understand :-)
So I wonder how the author of the linked question got his setup to work at all with the setup in rendered(). Any ideas anyone?
Update: It turns out I made a simple mistake which I did not spot until this morning.
I had id="new-customer-name" in the template and tried to register the filed with parsley using #new_customer_name. This cannot work and what is more, hyphens cannot be used for id-strings. After correcting the error it worked.
I guess you need to add the data-parsley-validate as given below. if its working without using that let me know. I am wondering how did it render with using data-parsley-validate in form.
form id="new_customer_form" data-parsley-validate