Angularjs 使用ng更改将值从ng模型传递到另一个ng模型时出错

Angularjs 使用ng更改将值从ng模型传递到另一个ng模型时出错,angularjs,twitter-bootstrap,angularjs-scope,angularjs-ng-model,angularjs-ng-change,Angularjs,Twitter Bootstrap,Angularjs Scope,Angularjs Ng Model,Angularjs Ng Change,对于“a.html”的第一个输入,用户可以从下拉列表中选择或输入值 对于第二个输入,默认值设置为与第一个输入相同。用户可以稍后更改第二个输入中的值。然后,来自第二个输入的值将传递到b.js的函数setPath 在第一个输入中输入一个值“android”后,第二个输入也将默认为“android”。在删除第二次输入中的所有值并尝试输入新值后,出现控制台错误。 它说“无法在字符串‘android’上创建属性名” a、 html // first input <input type="text"

对于“a.html”的第一个输入,用户可以从下拉列表中选择或输入值

对于第二个输入,默认值设置为与第一个输入相同。用户可以稍后更改第二个输入中的值。然后,来自第二个输入的值将传递到b.js的函数setPath

在第一个输入中输入一个值“android”后,第二个输入也将默认为“android”。在删除第二次输入中的所有值并尝试输入新值后,出现控制台错误。 它说“无法在字符串‘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(){
if(!$scope.result.c |$scope.result.c&&$scope.result.c.id){
返回;
}否则{
var c=$scope.result.c;
对于(变量i=0;i<$scope.cs.length;i++){
if(c==$scope.cs[i].name){
$scope.result.c=$scope.cs[i];
返回;
}
}
}
};
b、 js

函数setPath(){
$modal.open({
templateUrl:“/xxx/a.html”,
范围:范围,,
控制器:“控制器”,
windowClass:'aModal'
}).result.then(函数(结果){
//scope.result.path.name与a.html中的第二个输入值相同
var anchorTag='';
}
如果我在a.html中更改第一个输入的ng change代码,则在将光标移出第一个输入后,第二个输入的值不会显示。twitter引导bs选项仍然是新的

<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" />

//第二输入

<input type="text" ng-disabled="!result.c.id" ng-model="result.path"/>


这没有什么意义。在
type=text
的第一个输入框中,您的
ng模型是
result.c
,这将使
result.c
成为一个字符串。但是,您稍后会像引用对象一样引用它,并尝试使用
result.c.id
result.c.name
,等等,因为它是一个string,它也被复制为字符串,意思是
result.path
也是一个字符串,因此
result.path.name
也不起作用。也许你的
ng模型
应该是
result.c.name
?什么是
bs options
指令?它是第三方库吗?如果是,可能是该指令导致了问题lem,您应该联系该库的客户支持。bs-options是twitter引导库我希望将b.js anchorTag值设置为与a.html中的第二个输入相同的值(如果用户稍后更改了第二个输入的值,则希望b.js anchorTag值与第二个输入相同)。如果我将ng模型更改为result.c.name,则b.js anchorTag值与第一个输入的值相同。希望与第二个输入的值相同。
<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" />
<input type="text" ng-disabled="!result.c.id" ng-model="result.path"/>