angularjs service doesn't see array - arrays

I'm trying to build a forum. I have a service and when i do console.log() on the service I see this
Constructor {page: "thread", showReplyForm: false, newPosts: Array[0], boardID: null, threadID: "24"}
boardID: null
newPosts: Array[1]
created: 1412040853
id: "56"
message: "test22"
score: 0
why is it that on top it says newPosts: array[0]
but when i expand it underneath, it says newPosts: array[1]
Also when I do service.newPosts.length, I get 0. How do I see that 1? I can't paste the rest of the code here because it's too long.

Related

Solana Web3.js: Getting `null` for Mint account, althought it should return an `AccountInfo` object

When I run connection.getAccountInfo(watermelonMint.key); I get a null object, although it should return an AccountInfoObject. Any idea why this is the case? When I look for the address associated with this mint on solana explorer, I get normal statistics (https://explorer.solana.com/address/7vLEZP5JHhKVg3HEGSWcFNaxAKg7L633uMT7ePqmn98V?cluster=devnet)
console.log("Watermelon mint is: ");
console.log(watermelonMint);
returns
Mint {conn: Connection, key: PublicKey}
conn: Connection {_commitment: undefined, _confirmTransactionInitialTimeout: undefined, _rpcEndpoint: 'https://api.devnet.solana.com', _rpcWsEndpoint: 'wss://api.devnet.solana.com/', _rpcClient: ClientBrowser, …}
key: PublicKey
_bn: BN {negative: 0, words: Array(11), length: 10, red: null}
[[Prototype]]: Struct
[[Prototype]]: Object
any idea what could cause this?
Update 1:
basically, Token.getMintInfo(); keeps failing
const token = new Token(conn, mint, TOKEN_PROGRAM_ID, {} as any)
console.log("Getting token: ", token);
let out: Promise<MintInfo> = token.getMintInfo();
console.log("Out is: ", out);
Most likely, mint in "Update 1" is incorrect, or that your connection is improperly defined somewhere. Can you double-check that mint is equal to PublicKey("7vLEZP5JHhKVg3HEGSWcFNaxAKg7L633uMT7ePqmn98V")?
Also, can you make sure to await the response from token.getMintInfo()?

Accessing labels and confidence values with Tensorflow.js custom model?

(EDIT: partly solved, please see the end of the post) I have successfully uploaded a custom Tensorflow.js classifier that makes predictions of my webcam feed. It's trained on two classes, "good" and "bad". I get results as an array (correct me if I'm using the terms wrong as I'm a newbie!)
As the next step, I want to print the labels and confidence values on my browser. However, I find it a bit hard to grasp how I access my "good" and "bad" labels and confidence values from this result format that I get:
const result = await model.predict(t4d);
console.log(result);
(console)
t {kept: false, isDisposedInternal: false, shape: Array(2), dtype: "float32", size: 2, …}
dataId:
__proto__: Object
dtype: "float32"
id: 685817
isDisposedInternal: false
kept: false
rankType: "2"
scopeId: 883969
shape: (2) [1, 2]
size: 2
strides: [2]
isDisposed: (...)
rank: (...)
__proto__: Object
If I understand right, it gives me shape 2 = class 2 as a result (or is it just the shape and not my class yet?). Can anybody give advice on how to manually assign labels for these shapes 1 and 2 so that they can be printed? And how would I access confidence values - with argMax?
Ideally I would want it print something like this:
Good: 0.703
Bad: 0.298
Reference is this out-of-the-box mobilenet example from Tensorflow.js tutorials:
const webcam = await tf.data.webcam(webcamElement);
while (true) {
const img = await webcam.capture();
const result = await net.classify(img);
document.getElementById('console').innerText = `
prediction: ${result[0].className}\n
probability: ${result[0].probability}
`;
Where it prints the most probable class label and confidence value (like cat, 0.3444).
Warm thanks for any help!
EDIT: By following this tutorial, I was able to extract the label by making an array of my labels:
const labels = ["good", "bad"];

Json Object Length is returning zero Javascript

This is my json object adminDocs in angularJS.
[] 0: {rowno: 1, docTypeDesc: "Passport photocopy", …} 1: {rowno: 2, docTypeDesc: "Birth Certificate", …} 2: {rowno: 3, docTypeDesc: "Admission Doc Literature", …} 3: {rowno: 4, docTypeDesc: "Transcript", …} length: 4 __proto__: Array(0)
Checking $scope.adminDocs.length is returning zero.
Try something like this
var count = Object.keys(adminDocs).length;
Try to parse the object and then use:
var obj = JSON.parse(*your JSON*);
var length = Object.keys(obj).length;
My issue is not with $scope.adminDocs.length returning zero. The object's value is not returned untill it is completely loaded. So, it is returning zero.

Why do I get undefined value when I reuse it while pushing the key-value pairs into the $scope object?

I am trying to add the comment to the $scope.comments array. All key-value pairs are being pushed into $scope.comments except for the initial key. Which has to shorten the capitaliseUsername(comment.owner).
$scope.comments.push({
id: comment.id,
text: comment.text,
timestamp: comment.timestamp,
owner: comment.owner,
card: comment.card,
initial: capitaliseUsername(comment.owner) //why is comment.owner value undefined here
}
Yet comment array returned from the server contains comment.owner value because the owner key works perfectly.
Check the screenshot of the JSON data returned for the comments.
The function capitaliseUsername(comment.owner) have to need return something that assign in "initial" in comments array;
Here comment.owner is ok but as the capitaliseUsername(comment.owner) has no return and for this "initial" is assign with undefined.

AngularJS - wrong input validation status

I have an input and on ng-change i pass the Form.input in a function so i can do some stuff based on the inputs status (errors, valid/invalid...). But here is the weird thing:
When i log the input i passed, i see in the console output that input.$valid = false which is the correct value. But when i log input.$valid itself i get that it is true which is false! Why is this happening??? When i try to parse input.$valid i get wrong value and i cannot do calculations based on that.
Here is the input:
<input ng-model="..."
type="radio"
name="input"
ng-value={{v}}
ng-disabled="field.readonly"
ng-required="field.required"
ng-init="test(Form.input)"
ng-change="test(Form.input)">
And here is the test function:
$scope.test = function (object) {
console.log(object);
console.log(object.$valid);
console.log(JSON.stringify(object));
};
and here is the log output:
// console.log(object);
c {$viewValue: NaN, $modelValue: NaN, $parsers: Array[1], $formatters: Array[1], $viewChangeListeners: Array[1]…}
$dirty: false
$error: Object
$formatters: Array[1]
$invalid: true
$isEmpty: function (a){return F(a)||""===a||null===a||a!==a}
$modelValue: undefined
$name: "input"
$parsers: Array[1]
$pristine: true
$render: function (){c[0].checked=d.value==e.$viewValue}
$setPristine: function (){this.$dirty=!1;this.$pristine=!0;g.removeClass(e,yb);g.addClass(e,Pa)}
$setValidity: function (a,c){p[a]!==!c&&(c?(p[a]&&n--,n||(k(!0),this.$valid=!0,this.$invalid=!1)):(k(!1),this.$invalid=!0,this.$valid=!1,n++),p[a]=!c,k(c,a),l.$setValidity(a,c,this))}
$setViewValue: function (d){this.$viewValue=d;this.$pristine&&(this.$dirty=!0,this.$pristine=!1,g.removeClass(e,Pa),g.addClass(e,yb),l.$setDirty());r(this.$parsers,function(a){d=a(d)});this.$modelValue!==
$valid: false
$viewChangeListeners: Array[1]
$viewValue: undefined
__proto__: Object
// console.log(object);
true
// console.log(JSON.stringify(object));
{"$viewValue":null,"$modelValue":null,"$parsers":[null],"$formatters":[null],"$viewChangeListeners":[null],"$pristine":true,"$dirty":false,"$valid":true,"$invalid":false,"$name":"input","$error":{}}
UPDATE: I think i might have found something. When i do:
<input ...
ng-init="{{test(Form.input)}}"
ng-change="{{test(Form.input)}}">
instead of
<input ...
ng-init="test(Form.input)"
ng-change="test(Form.input)">
i get the correct result, but i also get an error in console:
Error: $parse:syntax
Syntax Error: Token 'test' is at column {2} of the expression [{3}] starting at [{4}].
I believe that there's nothing wrong with your code, it's just the way you are reading the console output.
By doing console.log(object) you are "printing" the JavaScript representation of the object. It's like if you were looking directly to the object's reference. This means that if the object is changed afterwards, you will see those changes as well. Think in it like the realtime representation of the object.
On the other logs (console.log(object.$valid); and console.log(JSON.stringify(object));) that doesn't happen because you are just printing strings/booleans, no object representations.
If you want to check the real object's content, stick to the:
console.log(JSON.stringify(object));

Resources