I've got basic variable that I'm getting from my api:
nurseListSpeciality.avatar = "srcs[14]"
I want to change srcs[14] into array name, that my object should be like:
nurseListSpeciality:[{avatar: srcs[14]}]
The main problem is that I don't want to execute the reference on the array, but I want to put just a name of it inside my object.
This is why I failed to use eval(). Eval is trying to get srcs[14] value and put it into my object. This is not what I want.
If you're open to use lodash, using _.get is a good way to do this:
nurseListSpeciality.avatar = _.get(window, "srcs[14]");
This code assumes that srcs is a variable which is available globally (in window object). If you have some other scope, you should replace window with the appropriate object.
vuejs console gives:
Uncaught (in promise) TypeError: this.nurseListSpeciality[i].eval is
not a function
Error message tells you that this.nurseListSpeciality[i] doesn't have an eval method, you need to invoke global eval on this.nurseListSpeciality[i].avatar as.
eval(this.nurseListSpeciality[i].avatar)
Note
This will not work if you don't have a variable srcs available in your current scope.
Related
I will try to explain my problem. I have an array of a particular object and, from this array, I want to create a new one with the value of a particular field of each object.
In order to achieve this, I tried to use array.forEach() method but I get a variable undefined error inside the forEach() function. This is my code:
var values: number[];
measures.forEach((measure)=>{
values.push(measure.value);
});
I've tried to declare the array values as public (and access this.values) and also to declare it in the function where I make the forEach and neither way worked.
Here is the error I get in the browser (angular CLI reports no problem):
ERROR TypeError: "values is undefined"
Try to initialize your array rather than just declare it as
values: number[] = [];
You do not need the var keyword in angular if you are declaring a variable directly inside a component class. If you need to do it inside a function, use let keyword. more information HERE
I'm creating a simple web page where i display a button which execute this code
$window.open(link, "_self");
The link variable is a simple telegram link for a channel, but this is not the problem, the problem, as the question say itself, is about arguments variable in $window.open.
This in my opinion is strange because when i logged in the console $window.open function, i received this output:
function pbWindowOpen() {
lastBlockCaller = {
caller: arguments.callee.caller,
args: arguments.callee.caller.arguments
};
try {
return newWindowOpenFn.apply(this, argument…
At this point, should not i see an argument variable inside this function? How could i solve this problem?
Passing some arguments could resolve my problem? If yes, there's an answer about why i'm having arguments null?
I've also tried with window.open but nothing changes, always the same problem
That shouldn't happen if you are running your code in a browser (in other env you may have some initialized variable window representing something else), $window is a wrapper in top of var currWindow = $window.self || $window.window and then do a perform of callong open(...) function. Hence, you neither using the native javascript code badly in a angular context, and again that would be easily mock-ableif we mock $window and create a property call self or window inside it. So it will work in the application, and will also be testable.
I got an object like:
$scope.project = {name: 'whatever', description: 'blabla', another: 'another'};
To debug this, I enter in repl mode and try to see what "project" has.
When I define project variable as below, and call it, it returns my object, but when I try to access its keys (project.name), I get undefined. If I do Object.keys(project) I am getting the page object methods like click, getAttribute, etc.
Any ideas on how can I have access to the original object keys?
View side:
<h1 id="foo">{{project.name}}</h1>
Test side:
var project = element(by.id('foo')).evaluate('project');
evaluate uses executeScript behind the scenes. It returns an ElementFinder which resolves to the object you are looking for:
var project;
element(by.id('foo')).evaluate('project').then(function(value) {
project = value;
});
The documentation says:
which resolves to the evaluated expression for each underlying
element. The result will be resolved as in
webdriver.WebDriver.executeScript. In summary - primitives will be
resolved as is, functions will be converted to string, and elements
will be returned as a WebElement.
Also, check out Accessing Angular inside Protractor Test
Edit: syntax error
I want to add another name under subChild in Object. Do we have any method for doing this. In subdomain I have another name. Which I need to add under subchild.
I tried
childBD[i].subChild.push(busDomain);
I also tried
childBD[i].subChild.concat(busDomain);
but it is throwing an error
TypeError: childBD[i].subChild.push is not a function.
Can anyone please help me resolving this.
From the picture above I see that subChild is an object and not an array. So there are no functions like push() or concat() for an object. You can add a property to it like this childBD[i].subChild.busDomain = busDomain;
I have written a custom module which creates a block. I invoke the block from a template file using the following code.
$block = module_invoke('my_mod', 'block_view', 'block_1a', $an_argument);
print $block['content'];
I need to access $an_argument in the module when the block is created.
How can I access the argument I pass to the block when it's invoked?
I believe you would have to implement the hook_block_view to handle your argument.
The api docs for hook_block_view