I want to display some default template in text area at very first loading.I tried to get that output but my code doesn't work.I put all breakpoints that value change.that also doesn't work. When second time data will display on text area.
<textarea meditor style="height: 100%;margin-top: 10px;border: 1px solid lightgray;" ng-model="activity.GoCode" name="gocode" required>{{activity.GoCode}}</textarea>
function getGoCode(data) {
if (data.GoCode == undefined) {
$scope.activity.GoCode = "test";
} else {
$scope.activity.GoCode = data.GoCode;
};
}
I Found solution for this
I set a value initially for this variable (activity.GoCode) before that I create
'$scope.activity' object and then assign value for when data is loaded.
$scope.ReadSampleGoFile = function () {
$http.get('settings/sampleGO.txt').then(function (data) {
//use the file data here
// console.log(data.data);
$scope.activity=[];
$scope.activity.GoCode=data.data;
});
}
When does your function getGoCode() is called, upon page load ?
I see one issue with your code even if it is not probably the problem here, having:
ng-model="activity.GoCode"
and
{{activity.GoCode}}
is redundant as explain here and will cause an exception in Internet explorer (Error: Invalid Argument) as explain here
Also what is the meditor directive doing, it is possible that this directive is the source of your problem as I don't see why your code would not work
I'm seeing an error when I remove an element from an array in a collection. I'm removing the element by index.
What's weird is that the server code works but in the console I see an error "Exception while simulating the effect of invoking '/patterns/update' Error: documentMatches needs a document".
I've spent ages trying to work out what the problem is and I'm stumped! See the code below for a minimal example that reproduces the problem.
(The only references I can find to this error don't seem relevant - I think this poster was identifying elements by attributes not index:
Removing an object from an array inside a Collection. And this post seems to relate to Angular, which I'm not using, and the question doesn't seem to have been answered: Minimongo errors when I try to update a document containing an array)
Any ideas why the query might fail on the client but not the server? The error happens at the point when I pull the element from the array with
Patterns.update({_id: pattern_id}, {$pull : {"my_array" : null}});
Full code:
HTML
<head>
<title>Array test</title>
</head>
<body>
{{> hello}}
</body>
<template name="hello">
<p>Values in the array: {{array}}</p>
<button class="add">Add item to array</button>
<button class="remove">Remove item from array</button>
</template>
JavaScript:
Patterns = new Mongo.Collection('patterns');
if (Patterns.find().fetch().length == 0)
{
Patterns.insert({name: "My document", my_array: [0] });
}
if (Meteor.isClient) {
Template.hello.helpers({
array: function () {
return Patterns.find().fetch()[0].my_array;
}
});
Template.hello.events({
'click button.add': function () {
pattern_id = Patterns.find().fetch()[0]._id;
var new_value = Patterns.findOne(pattern_id).my_array.length;
Patterns.update({_id: pattern_id}, {$push: {my_array: new_value}});
},
'click button.remove': function() {
pattern_id = Patterns.find().fetch()[0]._id;
var index = Patterns.findOne(pattern_id).my_array.length -1;
var obj = {};
obj["my_array." + index ] = "";
Patterns.update({_id: pattern_id}, {$unset : obj});
// THIS LINE CAUSES THE CONSOLE ERROR
Patterns.update({_id: pattern_id}, {$pull : {"my_array" : null}});
}
});
}
You are encountering a current limitation of Minimongo, that is mentioned in the source here
// XXX Minimongo.Matcher isn't up for the job, because we need
// to permit stuff like {$pull: {a: {$gt: 4}}}.. something
// like {$gt: 4} is not normally a complete selector.
// same issue as $elemMatch possibly?
However if you check your collection after that exception you will see that the item has been removed from your array. This would have happened on the server side (with the real MongoDB, then synchronised back with your client side collection), as this error is only impacting the client side latency compensation operation on the client collection, which is then corrected when the update arrives from the server.
My suggestion given that you are encountering minimongo limitations would be to move your updates into meteor methods where you always interact mongodb on the server, though you will need to add stub methods to handle any latency compensation you require on the client.
10 $digest() iterations reached. Aborting!
There is a lot of supporting text in the sense of "Watchers fired in the last 5 iterations: ", etc., but a lot of this text is Javascript code from various functions. Are there rules of thumb for diagnosing this problem? Is it a problem that can ALWAYS be mitigated, or are there applications complex enough that this issue should be treated as just a warning?
as Ven said, you are either returning different (not identical) objects on each $digest cycle, or you are altering the data too many times.
The fastest solution to figure out which part of your app is causing this behavior is:
remove all suspicious HTML - basically remove all your html from the template, and check if there are no warnings
if there are no warnings - add small parts of the html you removed and check if the problem is back
repeat step 2 until you get a warning - you will figure out which part of your html is responsible for the problem
investigate further - the part from step 3 is responsible for either mutating the objects on the $scope or is returning non-identical objects on each $digest cycle.
if you still have $digest iteration warnings after step 1, than you are probably doing something very suspicious. Repeat the same steps for parent template/scope/controller
You also want to make sure you are not altering the input of your custom filters
Keep in mind, that in JavaScript there are specific types of objects that don't behave like you would normally expect:
new Boolean(true) === new Boolean(true) // false
new Date(0) == new Date(0) // false
new String('a') == new String('a') // false
new Number(1) == new Number(1) // false
[] == [] // false
new Array == new Array // false
({})==({}) // false
Usually that happens when you're returning a different object every time.
For example, if you use this in a ng-repeat:
$scope.getObj = function () {
return [{a: 1}, {b: 2}];
};
You're going to get this error message because Angular tries to have the "stability" and will execute the function until it returns the same result 2 times (comparing with ===), which in our case will never return true because the function always returns a new object.
console.log({} === {}); // false. Those are two different objects!
In this case, you can fix it by storing the object in scope directly, e.g.
$scope.objData = [{a: 1}, {b: 2}];
$scope.getObj = function () {
return $scope.objData;
};
That way you're always returning the same object!
console.log($scope.objData === $scope.objData); // true (a bit obvious...)
(You should never encounter that, even on complex applications).
Update: Angular has added some more in-depth explanation on their website.
Just wanted to throw this solution in here, hopefully it'll help others. I was getting this iteration problem because I was iterating over a generated property which was making a new object every time it was called.
I fixed it by caching the generated object the first time it was requested, and then always returning the cache if it existed. A dirty() method was also added, which would destroy the cached results as needed.
I had something like this:
function MyObj() {
var myObj = this;
Object.defineProperty(myObj, "computedProperty" {
get: function () {
var retObj = {};
return retObj;
}
});
}
And here's with the solution implemented:
function MyObj() {
var myObj = this,
_cached;
Object.defineProperty(myObj, "computedProperty" {
get: function () {
if ( !_cached ) {
_cached = {};
}
return _cached;
}
});
myObj.dirty = function () {
_cached = null;
}
}
There also is the possibility of it not being an infinite loop at all. 10 iterations is not a sufficiently large number to conclude that with any amount of certainty. So before going on a wild-goose chase it may be advisable to rule out that possibility first.
The easiest method to do so is increasing the maximum digest loop count to a much larger number, which can be done in the module.config method, using the $rootScopeProvider.digestTtl(limit) method. If the infdig error does no longer appear you simply have some sufficiently complex update logic.
If you build data or views relying on recursive watches you may want to search for iterative solutions (i.e. not relying on new digest loops to be started) using while, for or Array.forEach. Sometimes the structure is just highly nested and not even recursive, there probably is not much to be done in those cases except raising the limit.
Another method of debugging the error is looking at the digest data. If you pretty print the JSON you get an array of arrays. Each top level entry represents an iteration, each iteration consists of a list of watch entries.
If you for example have a property which is modified in a $watch on itself it is easy to see that the value is changing infinitely:
$scope.vm.value1 = true;
$scope.$watch("vm.value1", function(newValue)
{
$scope.vm.value1 = !newValue;
});
[
[
{
"msg":"vm.value1",
"newVal":true,
"oldVal":false
}
],
[
{
"msg":"vm.value1",
"newVal":false,
"oldVal":true
}
],
[
{
"msg":"vm.value1",
"newVal":true,
"oldVal":false
}
],
[
{
"msg":"vm.value1",
"newVal":false,
"oldVal":true
}
],
[
{
"msg":"vm.value1",
"newVal":true,
"oldVal":false
}
]
]
Of course in larger project this may not be as simple, especially since the msg field often has the value "fn: regularInterceptedExpression" if the watch is a {{ }} interpolation.
Other than that the already mentioned methods, like cutting down the HTML to find the source of the problem, are of course helpful.
I had the same problem - I was creating a new date every time. So for anyone dealing with dates I converted all calls like this:
var date = new Date(); // typeof returns object
to:
var date = new Date().getTime(); // typeof returns number
Initializing a number instead of a date object solved it for me.
the easy way is :
use angular.js,not the min file.
open it and find the line:
if ((dirty || asyncQueue.length) && !(ttl--)) {
add line below:
console.log("aaaa",watch)
and then refresh your page, in the develope tools console,you will
find you error code .
It's a known bug in ui-router, this helped us: https://github.com/angular-ui/ui-router/issues/600
I would also like to mention that I received this error message when I had a typo in the templateUrl of a custom directive that I had in my project. Due to the typo, the template could not be loaded.
/* #ngInject */
function topNav() {
var directive = {
bindToController: true,
controller: TopNavController,
controllerAs: 'vm',
restrict: 'EA',
scope: {
'navline': '=',
'sign': '='
},
templateUrl: 'app/shared/layout/top-navTHIS-IS-A-TYPO.html'
};
Look in the network tab of your web browser's dev tools, and look to see if any resource is having a 404 error.
Easy to overlook, because the error message is very cryptic and seemingly unrelated to the real issue.
I was having this issue in my project because the .otherwise() was missing my route definition and I was hitting wrong route.
I had this issue because I was doing this
var variableExpense = this.lodash.find(product.variableExpenseList, (ve) => {
return ve.rawMaterial.id = rawMaterial.id;
});
Instead of this: (notice = vs ===), my unit test started breaking and I found my stupidity
var variableExpense = this.lodash.find(product.variableExpenseList, (ve) => {
return ve.rawMaterial.id === rawMaterial.id;
});
I ran into this issue where I needed a dynamic tooltip... it caused angular to recalculate it every time as a new value (even though it was the same). I created a function to cache the computed value like so:
$ctrl.myObj = {
Title: 'my title',
A: 'first part of dynamic toolip',
B: 'second part of dynamic tooltip',
C: 'some other value',
getTooltip: function () {
// cache the tooltip
var obj = this;
var tooltip = '<strong>A: </strong>' + obj.A + '<br><strong>B: </strong>' + obj.B;
var $tooltip = {
raw: tooltip,
trusted: $sce.trustAsHtml(tooltip)
};
if (!obj.$tooltip) obj.$tooltip = $tooltip;
else if (obj.$tooltip.raw !== tooltip) obj.$tooltip = $tooltip;
return obj.$tooltip;
}
};
Then in the html, I accessed it like this:
<input type="text" ng-model="$ctrl.myObj.C" uib-tooltip-html="$ctrl.myObj.getTooltip().trusted">
this is how I approached it and found a solution:
I checked the text, it showed:
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"statement === statment && functionCall()","newVal":[{"id":7287,"referen...
so if you can see the
msg
that's the statment generating the error. I checked the function called in this message, I returned (false) from all of them just to determine which one have the problem.
one of them was calling a function that keeps changing the return, which is the problem.
As crazy as it sounds, I fixed this error just by restarting my browser when it just cropped up all of a sudden.
So one solution is to just clear your browser's cache or try restarting the browser.
I got a qx.ui.form.Spinner object and I am setting the initial value from an XML file. The value is unfortunately returned as a string, which leads to the following confusing error in Firebug:
Error in property value of class qx.ui.form.Spinner in method setValue with incoming value '3': Is invalid!
Running this sample in the Playground doesn't produce any error, but the spinner is not being set:
// Create a button
var button1 = new qx.ui.form.Button("First Button", "icon/22/apps/internet-web-browser.png");
// Document is the application root
var doc = this.getRoot();
var spinner = new qx.ui.form.Spinner(1, 1, 60);
doc.add(spinner);
// Add button to document at fixed coordinates
doc.add(button1,
{
left : 100,
top : 50
});
// Add an event listener
button1.addListener("execute", function(e) {
spinner.setValue("3");
});
So my questions are:
should the string value be working? So far it seemed to be seldom a problem when number are actually string.
should the Playground give an error?
To answer your questions:
No, the string value will not work. Try using the parseInt() function to convert the string into an integer.
Actually the Playground is giving a problem, but the exception is not handled by the Playground, Try adding a try .. catch and you will see the exact same errormessage you already know.
try {
spinner.setValue("3");
} catch (e) {
alert(e);
}
Thanks.
I already uses parseInt() to get it worked and I submitted a bug report: http://bugzilla.qooxdoo.org/show_bug.cgi?id=4457
I daresay the Playground should at least log the error in its "Log" window. You might want to consider opening a bug for this.
My form in the html DOM is a checkbox to click (there can be more than one). The problem occurs in the description string when ever I use an apostrophe, since my list object is single-quote deliniated. This is one of the checkboxes in the form:
<input type="checkbox" id="cbx" name="cbx" value="{'getPic': 'url', 'picsrc': 'http://lh3.ggpht.com/_ZB3cttqooN0/SVmJPfusGWI/AAAAAAAADvA/GuIRgh6eMOI/Grand%20Canyon%201213_121508214.JPG', 'pos': None, 'description': 'Here's what it REALLY looks like at 5:30am! Bring your headlight!'}">
The javascript that reads the values of the checked checkboxes and pushes them into an array (list):
var pylist = [];
for (i=0; i<document.picList.cbx.length; i++) {
if (document.picList.cbx[i].checked) {
pylist.push( document.picList.cbx[i].value );
}
}
var getstr = JSON.stringify(pylist);
The problem is always that getstr at this point has chopped off everthing after the single quote in the description property.
I've tried different ways of escaping it to little avail.
The problem is that the value of the checkbox already is a JSON string. One solution would be to call JSON.parse() on the value:
var pylist = [];
for (i=0; i<document.picList.cbx.length; i++) {
if (document.picList.cbx[i].checked) {
pylist.push( JSON.parse( document.picList.cbx[i].value) );
}
}
var getstr = JSON.stringify(pylist);
I've run into the same issue - we stick json in a hidden field so we don't have to query the server on every page. We replace apostrophes with a "code" before putting into the html - we added a javascript function that replaces the code with an apostrophe.
Really hacky, but it works really well. Of course, we have one place in the code that gets json from the server and one place where javascript needs to parse it - if you find you're repeating the methods throughout your code, your mileage will vary.