Angular 8 static query usage and migration from Angular 7 - angular7

I am seeing a crash in a component usage when I use {static: true}
Cannot read property 'nativeElement' of undefined: "TypeError: Cannot read property 'nativeElement' of undefined
Component code looks like this
#ViewChild('filterInput', {static: true}) filterInputElement: ElementRef;
ngAfterViewInit() {
this.inputNodeRef = this.filterInputElement.nativeElement;
}
My expectation based on the documentation here is that when I say {static: true}, my ViewChild is safe to access and use in ngAfterViewInit because it became available much earlier in ngOnInit - https://angular.io/guide/static-query-migration
Is this understanding incorrect?
Any pointers are appreciated.
Thanks

Related

TypeError: Cannot read property 'init' of undefined

import {manager, ReactCBLite} from 'react-native-couchbase-lite';
ReactCBLite.init(8091, 'admin', 'admin123', e => {
console.log('initialized');
});
Running this code in react-native for ios getting TypeError: Cannot read property 'init' of undefined
From the documentation:
import Couchbase from "react-native-couchbase-lite";
Couchbase.initRESTClient(manager => {
// use manager to perform operations
});
It seems there is no only init method, but there are other init methods you should use.
Pay attention that there are also special steps needed to be taken for iOS.

BackboneJS view keeps returning not defined

I can't seem to initialize my view. I tried looking around to see if this was asked before, but none of the solutions were working for me. My backbonejs view is below:
class FRView extends Backbone.View
el: $ 'fr_view'
initialize: ->
console.log("created")
render: ->
console.log("here")
I'm attemtpting to intialize it inside of a partial using the code below:
:javascript
var curr_view = new FRView()
but I keep getting the following error:
Uncaught ReferenceError: FRView is not defined
I've also tried
:javascript
var curr_view = new Backbone.View.FRView()
Which lead to the following error:
Uncaught TypeError: Backbone.View.FRView is not a constructor
From chrome sources browser I can see that the FRView file is loaded. I've also tried wrapping it in document onload but that didn't help. Any idea what might be causing this issue?
I see two bugs, one you know about and one that you'll find out about soon.
The first problem (the one you know about) is caused by CoffeeScript's scoping system:
Lexical Scoping and Variable Safety
[...]
Although suppressed within this documentation for clarity, all CoffeeScript output is wrapped in an anonymous function: (function(){ ... })();
So your FRView ends up looking more or less like this in JavaScript:
(function() {
var FRView = ...
})();
and that means that FRView is only visible inside your CoffeeScript file.
The easiest solution is to put the class in the global scope:
class #FRView extends Backbone.View
or equivalently:
class window.FRView extends Backbone.View
Another common solution is to define a global namespace for your app and then put your class in that namespace:
class YourNameSpace.FRView extends Backbone.View
and say new YourNameSpace.FRView when instantiating it.
The other problem is that your el looks a bit confused:
el: $ 'fr_view'
There are two problems here:
That will be looking for an <fr_view> element in your HTML and you probably don't have such a thing. I'd guess that you really have something like <div id="fr_view"> or maybe <div class="fr_view">, in that case you'd want to say:
el: '#fr_view' # If you're using an id attribute.
el: '.fr_view' # If you're using a CSS class.
$ 'fr_view' will be executed when the JavaScript is loaded and the element might not exist at that time. The solution to this problem is to use just the select for el as above. There's no need to use a jQuery object for el, Backbone will do that for you when the view is instantiated.
As 'mu is too short' pointed out, the issue rooted from namespace/declaration issues. After googling around about namespace I skimmed through this and fixed the issue by changing my backbonejs view to:
class Portal.Views.FRView extends Backbone.View
el: $ '#FRView'
initialize: ->
console.log("created")
render: ->
console.log("here")
and instantiated it using:
:javascript
var frview = new Portal.Views.FRView();

#Component viewBindings is deprecated, what to use instead?

I'm experimenting with Angular 2 and Dart. By the end of this step of the tutorial the class DisplayComponent has a Component annotation with viewBindings set:
#Component(selector: 'display', viewBindings: const [FriendsService])// this viewBinding
#View(...)
class DisplayComponent {
...
}
Atom with the angular2-dart plugin tells me that viewBindings is deprecated. This seems in-line with the documentation.
I've tried simply removing the variable from the annotation but I get an Exception saying No provider for FriendsService. What should I be doing instead?
for the sake of completeness
In Alpha 46 is viewProviders (viewBindings => viewProviders) and providers (bindings => providers) up to date.
https://angular.io/docs/ts/latest/api/core/ComponentMetadata-class.html
https://github.com/angular/angular/blob/master/CHANGELOG.md

Silverstripe 3: removeByName not working

Good morning,
I've been trying to use the removeByName method and it doesn't work.
I'm basically trying to hide a field in my DataObject within the forms that's generated by ModelAdmin, which manages the object.
See sample code below:
///DataObject snippet...
class MyObject extends DataObject{
public static $db = array(
'Title' => 'Varchar',
'Desc' => 'Text',
'Template' => 'HTMLText',
);
//#Override
public function getCMSField(){
$fields = parent::getCMSField();
$fields->removeByName('Template'); /// DOESN'T WORK!!!
return $fields;
}
}//class
Note: I'm not getting any errors. I'm just still seeing the field on the forms (Add and Edit) as usual.
Any help appreciated, thanks.
Okay, I found the issue.
I was just going over the API again for the millionth time, and recognized that I've named the function wrong. See correction below:
///Correction, forgot to add the 's' at the end of both the function and the parent call.
public function getCMSFields(){
$fields = parent::getCMSFields();
}
I can understand an error not being generated in Apache logs for the function because it's legit. But as for the parent call, it should of generated an error since the method don't exists. (Theory: Perhaps, since the function was never actually being called, the parent call wasn't being executed and thus no errors [run-time error]).

How to define a method for the class 'Proxy' in Dart js-interop?

I'm currently calling a jQuery based plugin called Bootstrap Context Menu.
In order to call it, I need to use the Javascript Interop library. But when I call a jQuery method from it I receive the following warning:
The method 'jQuery' is not defined for the class 'Proxy'
Code snippet:
js.scoped(() {
js.context.jQuery('#canvas').contextmenu();
});
This was not happening before some dart/js-interop updates. What is the right way to get rid of this warning?
You get this warning because the new analyzer doesn't seem to be aware of the option Report 'no such member' warnings when class defines noSuchMethod() ( Reported at http://dartbug.com/10016 ). If you switch back to the legacy analyzer you shouldn't see this warning anymore.
That said if you want to use the new analyzer and get rid of this warning you can use the array notation like this :
js.context["jQuery"]('#canvas')["contextmenu"]();
But :
it's less readable particullary for method calls.
it's less efficient for method calls because 2 operations are done ( f = js.context["jQuery"] followed by f('#canvas') ) instead of 1 ( js.context.jQuery('#canvas') )

Resources