Javascript 角度:防止在页面编辑上编辑输入字段
我在创建和编辑页面上都使用了一个角度文件,但我想知道是否有办法阻止用户在/edit页面上编辑地理段的名称 geo region detail.html:Javascript 角度:防止在页面编辑上编辑输入字段,javascript,angularjs,Javascript,Angularjs,我在创建和编辑页面上都使用了一个角度文件,但我想知道是否有办法阻止用户在/edit页面上编辑地理段的名称 geo region detail.html: <nav> <a href="#">Geo Segments</a> : </nav> <h1 class="geo-region-name">{{ geoRegion.name || 'Create Geo Segment' }}</h1> <
<nav>
<a href="#">Geo Segments</a> :
</nav>
<h1 class="geo-region-name">{{ geoRegion.name || 'Create Geo Segment' }}</h1>
<form ng-submit="updateOrAddGeoRegion()" id="regionForm">
<div class="row">
<div class="control-group span2">
<label class="control-label label-unstyled font-size-14" for="inputId">Label</label>
<div class="controls">
<input type="text" id="inputId" placeholder="Short name" class="input-small" value="{{ geoRegion.label }}" ng-model="geoRegion.label" required="required">
</div>
</div>
<div class="control-group span4">
<label class="control-label label-unstyled font-size-14" for="inputName">Name</label>
<div class="controls">
<input type="text" id="inputName" placeholder="Region Name" class="input-large" value="{{ geoRegion.name }}" ng-model="geoRegion.name" required="required">
</div>
</div>
</div>
<div class="control-group">
<label class="control-label label-unstyled font-size-14" for="inputAddress">Address</label>
<div class="controls">
<input type="text" id="inputAddress" placeholder="Address" class="input-xlarge" value="{{ geoRegion.address }}" ng-model="geoRegion.address">
<google-map-geocoder></google-map-geocoder>
</div>
</div>
$scope.newGeoRegion = true
$scope.geoRegionId = ''
$scope.hours = Hours
console.log('$scope.hours', $scope.hours)
$scope.geoRegion = {
app_id: $scope.app_id
geoRegion_id: '',
latitude: 37.7879938,
longitude: -122.40743739,
name: '',
address: '',
radius: 500,
customer_id: $scope.customer_id,
active_daily_clear: false
}
与@Ian完全相同,但由于“”值和其他原因而有所改进
ng-disabled="isEdit(geoRegion)"
然后在控制器中
$scope.isEdit = function(geoRegion) {
if (angular.isUndefined(geoRegion.geoRegion_id))
return true;
if (geoRegion.geoRegion_id == '')
return true;
return false;
};
如果您决定使用不同的方法来检测编辑,您的isEdit()fn足以屏蔽视图(html)中的更改我是否应该假设如果填写了
georgion\u id
,则您正在编辑,否则您正在创建?如果是这样,请在名称文本框中添加一个属性,如ng disabled=“geoRegion.geoRegion\u id”
。另外,您是否有任何理由设置文本框的值属性<代码>ng型号
应该为youHi Ian处理这个问题,是的,这是正确的。如果填写了georgion\u id,则它正在编辑。ng disabled对我来说不起作用:(你有没有可能在JSFIDLE中给我看一个这样的例子,因为我无法让它工作?Name
有没有其他方法可以禁用/edit上的输入字段?当然,这里有一个例子:。注意文本框不能被聚焦/编辑(因为geoRegion\u id
属性有一个值)。将geoRegion\u id
属性更改为空字符串,单击顶部的“运行”按钮,然后注意文本框的可编辑性。