tadeuszwojcik / angular-once Goto Github PK
View Code? Open in Web Editor NEWOne time bindings for AngularJS
License: Do What The F*ck You Want To Public License
One time bindings for AngularJS
License: Do What The F*ck You Want To Public License
While the version is not minified I feel obligated to copy the code to my project(which gets minified on build before deploying).
Having a minified version is always good.
Hello!
Angular once- * not work in files which have been included using "ng-include"
<div once-if="thisNeverGetsDefined">
This will be rendered and not removed
</div>
This is trickier for ng-if, but for ng-show, can you add the ng-hide class name until the data gets defined, then either remove or leave it?
Should use transclusion instead of letting child elements/directive compiled/rendered.
Had several tests, in the following situation:
<div once-if="a" my-directive></div>
<div once-if="!a" my-directive><div>
both directive still get compiled even though their priority is lower. I suppose the the $element.remove() is queued after the compilation of other directives
It's not an issue report. Just a clarification request for the code "watcherRemover".
Here are the codes to watch until any defined value is given and then "remove $watch" by invoking removeWatcher(). I am not clear why the $watch will be removed when watcherRemover() is invoked.
// we do not have a valid value, so we register a $watch
var watcherRemover = $scope.$watch(watch, function (newValue) {
// wait until we have a valid value
if (newValue == undefined) return;
// remove this $watch
removeWatcher();
// if watching and binding $parsers are the same, use watching's value, else $parse the new value
return done(element, watcherParser == bindingParser ? newValue : bindingParser($scope));
});
function removeWatcher() {
if (watcherRemover) {
watcherRemover();
}
}
The following standard ng-code works as expected:
ng-attr-class="status-{{statusId}}"
I have tried to convert that to once-attr-* syntax:
once once-attr-class="'status-'+'statusId"
However, I get a "string is not a function" error. Anything that I missed?
TypeError: string is not a function
at setOneTimeBinding (once.js:14:25)
at https://localhost/once.js:161:9
at Object.forEach (angular.js:309:20)
at https://localhost/once.js:151:15
at nodeLinkFn (angular.js:6212:13)
at compositeLinkFn (angular.js:5622:15)
Calling a function in once-html that return the context is not working.
once-html="Sanitize(text)"
Older JavaScript engines don't have the forEach method.
Angular provides their own.
This should be used to provide better backward browser compatibility.
Hey!
Can I use angular-once to set value with $index on a option-element in a ng-repeat?
When I try to add ---once once-attr-value="$index" once-text="HRCvalue"--- I get this error in chrome console: "string is not a function" at "setOneTimeBinding (http://localhost:8100/lib/once.js:14:25)" (only once-text works)
as title said, this is not same as ngIf
. why it act like this?
Do you have an idea about how one might go about implementing a once-attr binding? I'm looking to bind to the tooltip
attribute required by bootstrap tooltips.
Thanks!
I can't seem to figure out the syntax for this, eg,
Is it possible without the full bind?
As title says :) It's not published to npm
/ bower
repositories
how to handle the ng-repeat-start and ng-repeat-end in angular-once ?
I'd like to use a angular-once with scope parameters.
Suppose I need to pass some value to my directives:
<div ng-repeat="item in items">
<directive-one ng-if="item.type === 'directive1'" value="{{item.value}}"></directive-one>
<directive-two ng-if="item.type === 'directive2'" value="{{item.value}}"></directive-two>
</div>
app.directive('directiveOne', function() {
return {
scope: {
value: '@'
},
restrict: 'E',
template: '<p once-text="value"></p>'
}
});
This will setup a watch using {{item.value}} and scope: value. How can I avoid it?
Thanks!
Hi,
I'm using once-src like so:
<img once-src="http://foo.com/image/{{ model.id }}/?size=200" />
But the directive doesn't work and spits out something like this :
<img once-src="http://foo.com/image/{{ model.id }}/?size=200" src="http://foo.com/image//?size=200" />
I've investigated a little, and it seems that when we arrive in the linking function, attrs['onceSrc']
is already interpolated to http://foo.com/image//?size=200
.
Your check in setOneTimeBinding then fails since value
is not undefined
.
I suppose this issue will apply to all interpolated values.
Cheers
The tag does not point at the correct version of once.js
, so bower install angular-once
installs v0.1.0
I think it would be useful in some cases to update content that has been bound-once. For example, if you change the locale of an app. In this case you'd want all of the bound-once content to update.
I've been watching @Pasvaz's bindonce rebind-debug branch and it's a nice feature, but it looks like that project is slowing down a bit. Perhaps because of ngBindOnce coming in 1.3? The problem is that ngBindOnce doesn't have this feature either.
Do you think it's something that could go into angular-once?
I expected
<input type="radio" once once-attr-name="'question-' + question.id" />
<input type="radio" once once-attr-name="'question-' + question.id" />
<input type="radio" once once-attr-name="'question-' + question.id" />
to result in
<input type="radio" name="question-1" />
<input type="radio" name="question-1" />
<input type="radio" name="question-1" />
but I get
<input type="radio" name="05T" />
<input type="radio" name="05W" />
<input type="radio" name="05Z" />
First of all wants to thank for this plugin. My page have lots of read only data which is rendered once. It helped me to reduce no of watches. I am still working on it to reduce more.
A small bug i found is if i use ng-if within ng-repeat then it works but not once-if. Without ng-repeat once-if works perfectly. Need help to fix it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.