Pass a string in function parameter - html

I try to call a function with a string as parameter
<input type="checkbox" value={{user.name}} id={{user.name}} ng-click="toggleSelection({{user.name}})">
but I have this error
Syntax Error: Token 'Marcus' is unexpected, expecting [)] at column 20 of the expression [toggleSelection(Julian Marcus)] starting at [Julian Marcus)].
i've tried toggleSelection('{{user.name}}') and toggleSelection("{{user.name}}") but still the same problem

Though #TOM has answered the question but doen't explained why it doen't work.
You should not use {{}} inside ng-click because ng-click does direct access do the scope variable without using interpolation {{}} directive.
The error you are finding because while evaluating toggleSelection({{user.name}}) this function $parser throws Syntax Error:
You could just fixed it by using direct scope variable.
ng-click="toggleSelection(user.name)"

You don't need angular to parse your string, just pass the object user.name
<input type="checkbox"
value="{{user.name}}"
id="{{user.name}}"
ng-click="toggleSelection(user.name)">
I've also added quotes around your value and id properties.

Related

Syntax error when calling a function with parameters in slim template

I have a slim template where I call a function like so:
textarea.form-control value = #function(parameter)
However I get the following error:
syntax error, unexpected '(', expecting ')'
Its strange that it does not like the '(" character because that's how I would imagine we would call functions with arguments from a template. What am I doing wrong and how can I call a function with an argument from a slim template. Apologies if this is a basic question, I am very new to slim and ruby
You don’t need the #:
textarea.form-control value = function(parameter)
As long as function and parameter are defined then this should work.
You may be confusing Ruby attributes (which use #) with functions/methods (which don’t). If you want to pass an attribute as the parameter, then you need the # in front of its name:
textarea.form-control value = function(#attribute)

MATLAB | Invalid syntax for calling function 'cond' on the path. Use a valid syntax or explicitly initialize 'cond' to make it a variable

I want to extract data from a table called cond. As you can see from line 75 in the screenshot shown below, data Diameter corresponding to Drake can be successfully extracted using cond('Drake',:).Diameter.
screenshot
However, when I was trying to write this into a function called findCF(), things went wrong at line 78 with an error message
Invalid syntax for calling function 'cond' on the path. Use a valid
syntax or explicitly initialize 'cond' to make it a variable.
Can anybody tell me how to modify my code?
cond() is the name of a built-in function. Matlab tolerates variables whose names collide with functions, but it can result in weird things like this. In the line that produces the error, Matlab thinks you are trying to call the function cond(), not access the variable cond.
Rename the variable to something else.

'Unable to invoke CFC - The data for must be no more than 100 characters in length

I'm trying to call a method as follows:
<cfinvoke component="#variables.target#"
method="#arguments.methodName#"
argumentcollection="#arguments.args#"
returnvariable="rtn">
</cfinvoke>
However, I am getting the following error:
Unable to invoke CFC - The data for 'param_value' must be no more than
100 characters in length.' faultDetail:''
The variable arguments.args is a struct and one of its elements looks like this:
{
param_name: 'property_uid',
param_value : '00000000-0000-0000-0000-0000000213131200,00002131300-0000-0000-0000-000000000000,00000000-0000-0000-0000-0000000002122,00000000-0000-0000-0000-000000032242
}
I know the problem is caused by this element, but don't know how to fix it.
Note that I've already updated the Maximum number of POST request parameters from 100 to 300 in the CF Administrator.
The variable property_uid is currently a list and the list's value is too long to be passed in as a struct key's value. Use listToArray() to send the data as an array. Inside the function, convert it back using arrayToList() if you need the data as a list again.
Please check the code of the invoked function (the function name can be found in your variable arguments.methodName in the component of variables.target).
Look for the tag <cfparam name="param_value" ...> and check if there is a maxlength attribute defined. It's probably set to 100 and thus causes ColdFusion to throw an exception if you pass more than 100 characters to said parameter.
Having a limit of 100 characters is probably a design descision on your side (database scheme?), so you need to figure this out by yourself.

Angularjs attribute literal value vs. expression evaluation

I'm having some trouble to understand how angularjs decides how to evaluate attributes. For exemple, using ng-repeat:
<div ng-repeat="item in items"></div>
the item in items part will be evaluated as an expression, looking for the content of items array set somewhere in the controller.
But using ng-src:
<img ng-src="/path/to/img/"></img>
the path/to/img/ will be considered a literal. If I want to make it 'dynamic' I must write:
<img ng-src="/path/to/img/{{id}}"></img>
where id is set in the controller.
Question: how do I choose which behaviour to follow when defining custom attributes for my custom directive?
There's nothing to choose from. Expressions in attribute values are interpolated by $interpolate service. And the latter uses $parse service to evaluate each expression in string.
Some directives (ng-if, ng-hide) expect nothing but expression in attribute, which is usually designated in API documentation. In this case the brackets can be omitted, and the expression will be evaluated within directive - $scope.$watch is being used often instead of calling $interpolate explicitly.
ng-repeat attribute syntax (it is referred as 'repeat expression' in documentation) is parsed by the directive itself and isn't related to Angular expressions.
Defining your attributes as expressions will give you huge possibility in directives chain - you will escape isolate scope error that made us all straggle. A specially chains with ng-repeat or another default ones.
What I saw in bootstrap code and started to use - I $eval expressions within own scope then passed to directives local variables instead of defining in isolate scope.
<div custom some-val='ctrl.data'></div>
//directive link or controller
var private = $scope.$eval($attrs.someVar);
Only con for $eval is that it's good for static variables. For dynamic you need either already evaluated value or best way is to put it into ng-model that can be shared between directives (fix me if I'm wrong)
Or just run watcher on result of expression that is much simpler.

using variable in argument - JSON target

I would like to use a variable (string) as part of my JSON target. Instead of simply coding for each section, like this:
$.each(data.portfolioitems.section1, function (k,v){...}
$.each(data.portfolioitems.section2, function (k,v){...}
$.each(data.portfolioitems.section3, function (k,v){...}
I would like to have a variable "varsection" that indicates which section should be called, like this:
$.each(data.portfolioitems.varsection, function (k,v){...}
As this exists, it seems that I am attempting to target the section "varsection", which of course doesn't exist.
I have found other topics where it was discussed how to use a variable as part of a JSON target, but it seems that none of the solutions I found are acceptable for this scenario where the target is an argument.
data.portfolioitems[varsection]