error passing value from a ng-model to another ng-model using ng-change
error passing value from a ng-model to another ng-model using ng-change
For the first input of 'a.html', user can select from the drop down list or enter a value.
For the second input, the default value is set to be the same as first input. User can later change the value in the second input. The value from the second input will then pass to function setPath for b.js.
After I have input a value 'android' in the first input, the second input will then default to 'android' as well. I am getting console error after I have removed all values in the second input and trying to input a new value.
It says " cannot create property name on string 'android'.
a.html
// first input
<input type="text" ng-model="result.c" data-auto-select="true"
ng-change="result.path = result.c; checkIfMatch()"
ng-blur="checkIfMatch()" bs-options="c as c.name for c in cs" />
// second input
<input type="text" ng-disabled="!result.c.id" ng-model="result.path.name"/>
a.js
$scope.checkIfMatch = function();
b.js
function setPath() {
$modal.open(
templateUrl: '/xxx/a.html',
scope: scope,
controller: 'aController',
windowClass: 'aModal'
).result.then(function(result)
// scope.result.path.name to be the same value as second input in a.html
var anchorTag = '<a href="' + result.c.id +'">Launch '+ result.path.name + '</a>';
if i change the code for ng-change of first input at a.html, the value doesn't show up for the second input after moving cursor out of the first input. Still new to twitter bootstrap bs-options.
<input type="text" ng-model="result.c" data-auto-select="true"
ng-change="result.path = result.c.name; checkIfMatch()"
ng-blur="checkIfMatch()" bs-options="c as c.name for c in cs" />
// second input
<input type="text" ng-disabled="!result.c.id" ng-model="result.path"/>
ng-model
type=text
result.c
result.c
result.c.id
result.c.name
result.path
result.path.name
perhaps your
ng-model
is supposed to be result.c.name
?– Claies
Aug 21 at 5:02
ng-model
result.c.name
What is the
bs-options
directive? Is it a third-party library? If so, maybe that directive is causing the problem and you should contact that library`s customer support.– georgeawg
Aug 21 at 5:05
bs-options
bs-options is twitter bootstrap library
– user21
Aug 21 at 5:18
I would like to set b.js anchorTag value to be the same value as the second input at a.html (If the value of second input is later changed by the user, would like b.js anchorTag value to be the same as second input). If I change the ng-model to be result.c.name, the b.js anchorTag value is folowing the same value as the first input. Would like it to be the same as the second input.
– user21
Aug 21 at 5:24
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
this doesn't really make sense. your
ng-model
in the first input box oftype=text
isresult.c
, which would makeresult.c
a string. however, you are later referring to it like it's an object, and trying to useresult.c.id
,result.c.name
, etc.. Because it's a string, it's also being copied as a string, meaningresult.path
is also a string, soresult.path.name
wouldn't work either.– Claies
Aug 21 at 4:59