【发布时间】:2015-01-29 16:10:17
【问题描述】:
我想在接收其他输入值的输入上使用 ng-model ...
我的代码不起作用,我不明白为什么,可以将 ng-model 设置为具有 Angular 值的输入吗?
我的代码
var BottomApp = angular.module('BottomApp', []);
BottomApp.controller('SeoArticle', ['$scope', function($scope) {
$scope.seoTitle = document.getElementById('title').value;
$scope.createSeoUrl = function(string){
var string;
string = string.replace(/'+/g, '');
string = string.replace(/"+/g, '');
return string.replace(/\s+/g, '-');
};
}]);
<div ng-controller="SeoArticle">
<input type="text" id="title" name="article[title]" class="form-control" placeholder="title" ng-model="seoTitle">
<input type="text" name="article[seo_title]" value="{{seoTitle2}}">
<input type="text" name="article[seo_url]" value="{{seoUrl2}}">
<div class="ui-block-title"><h5>{{seoTitle}}</h5></div>
<input type="text" id="title" class="form-control" placeholder="title" value="{{seoTitle}}" ng-model="seoTitle2">
<input type="text" id="seo_url" class="form-control" placeholder="seo_url" value="{{createSeoUrl(seoTitle)}}" ng-model="seoUrl2">
<div class="panel">
<div class="seo-overview">
<p class="seo-overview-title">{{seoTitle}}</p>
<p class="seo-overview-url">{{createSeoUrl(seoTitle)}}</p>
</div>
</div>
</div>
:
【问题讨论】:
-
我建议为这个问题构建一个简单的示例,以说明您所询问的概念。
-
我注意到的第一件事是 createSeoUrl 有一个名为“string”的参数,其中声明了一个名为“string”的变量。
-
是的,我改了,但这不是问题...
标签: angularjs