Angularjs 在两个输入上使用ng模型,值相同
我想对接收其他输入值的输入使用ng模型 我的代码不起作用,我不明白为什么,可以将ng模型设置为具有角度值的输入吗 我的代码Angularjs 在两个输入上使用ng模型,值相同,angularjs,Angularjs,我想对接收其他输入值的输入使用ng模型 我的代码不起作用,我不明白为什么,可以将ng模型设置为具有角度值的输入吗 我的代码 var BottomApp=angular.module('BottomApp',[]); BottomApp.controller('SeoArticle',['$scope',函数($scope){ $scope.seoTitle=document.getElementById('title')。值; $scope.createSeoUrl=函数(字符串){ var字
var BottomApp=angular.module('BottomApp',[]);
BottomApp.controller('SeoArticle',['$scope',函数($scope){
$scope.seoTitle=document.getElementById('title')。值;
$scope.createSeoUrl=函数(字符串){
var字符串;
string=string.replace(/'+/g',);
string=string.replace(/“+/g'”);
返回字符串。替换(/\s+/g,'-');
};
}]);
{{seoTitle}}
{{seoTitle}
{{createSeoUrl(seoTitle)}
这是一个工作模式
我已将ng应用程序调用添加到body标签
<body ng-app="BottomApp">
并从CreateSourl中删除了字符串变量声明
编辑:我认为你不能在DOM中完成。你应该使用一个观察者。查看更新的Plunker
$scope.$watch("seoTitle", function(newValue) {
$scope.seoTitle2 = newValue;
$scope.seoUrl2 = $scope.createSeoUrl(newValue);
})
<input type="text" id="title" class="form-control" placeholder="title" ng-model="seoTitle2">
<input type="text" id="seo_url" class="form-control" placeholder="seo_url" ng-model="seoUrl2">
$scope.$watch(“seoTitle”),函数(newValue){
$scope.seoTitle2=新值;
$scope.seoUrl2=$scope.createSeoUrl(newValue);
})
我建议为这个问题构建一个简单的示例,说明您正在询问的概念。首先我注意到CreateSourl有一个名为“string”的参数,其中声明了一个名为“string”的变量。是的,我更改了它,但这不是问题……不起作用,我的输入name=“article[seo_title]
和name=“article[seo_url]
必须填写……输入值ng model=“seoTitle2”
应为输入值ng model=“seoTitle”
和输入值name=“article[seo_title]”
应为输入值ng model=“seoTitle2“
。。。