반응형
AngularJS: ng-read only
텍스트에 부울을 전달하는 데 이상한 문제가 있습니다.여기 jsfiddle이 있습니다.
<div ng-app ng-controller="MainCtrl">
<p>First Name:
<input ng-model="first" ng-readonly="true"/>
</p>
<p>Last Name:
<input ng-model="second" ng-readonly="{{truefalse}}"/>
</p>
</div>
function MainCtrl($scope) {
$scope.first = "Angular";
$scope.second = "JS";
$scope.truefalse = "true";
}
왜 두 번째 필드를 수정할 수 있는지 설명해 주실 수 있나요?
스코프는 괄호 없이 ng-read only로 전달해야 합니다.$scope.truefalse는 문자열이 아니므로 따옴표는 필요 없습니다.
<div ng-app ng-controller="MainCtrl">
<p>First Name:
<input ng-model="first" ng-readonly="true"/>
</p>
<p>Last Name:
<input ng-model="second" ng-readonly="truefalse"/>
</p>
</div>
function MainCtrl($scope) {
$scope.first = "Angular";
$scope.second = "JS";
$scope.truefalse = true;
}
속성으로 모델 내부 요소를 사용할 때는 항상 곱슬곱슬한 중괄호를 사용할 필요가 없습니다만, 아래는 당신의 경우 정상적으로 동작하지 않는 코드가 동작하는 코드입니다.
<!DOCTYPE html>
<html ng-app="convertApp">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div ng-app ng-controller="MainCtrl">
<p>First Name:
<input ng-model="first" ng-readonly="true"/>
</p>
<p>Last Name:
<input ng-model="second" ng-readonly="{{truefalse}}"/>
</p>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<script>
var app = angular.module('convertApp', []);
app.controller('MainCtrl', function ($scope) {
$scope.first = "Angular";
$scope.second = "JS";
$scope.truefalse = "true";
});
</script>
</body>
언급URL : https://stackoverflow.com/questions/20903649/angularjs-read-only-input-with-ng-readonly
반응형
'programing' 카테고리의 다른 글
| 표현식에 대한 느린 각 일회성 바인딩 (0) | 2023.03.15 |
|---|---|
| 봄철 웹 소켓 인증 및 인가 (0) | 2023.03.10 |
| 스프링 보안 CORS 필터 (0) | 2023.03.10 |
| 부모 컨트롤러의 변수를 상속할 수 있습니까? (0) | 2023.03.10 |
| 페이지를 갱신하지 않고 URI를 변경하려면 어떻게 해야 합니까? (0) | 2023.03.10 |