简体   繁体   English

Angular ng 只读和位置搜索

[英]Angular ng read only and location search

Hello I have html file with angular.您好,我有带角度的 html 文件。 I am trying to set an input as read only, if I have a parameter in the URL.如果 URL 中有参数,我正在尝试将输入设置为只读。 Tried something like this but with no success尝试过这样的事情,但没有成功

<input type="text" name="firstName"  ng-readonly="$location.search().memRen" />

Maybe some solution with ngIf?也许ngIf的一些解决方案? I am not sure I am new to angular我不确定我是 angular 的新手

Services are not per definition available on the $scope object.服务不是根据$scope对象上的定义可用的。 Either you have to assign the service on the scope (not recommended!), or add a variable:您必须在范围内分配服务(不推荐!),或者添加一个变量:

function myController($scope, $location) {
    $scope.memRen = $location.search().memRen;
}

And in your html:在你的 html 中:

<input type="text" name="firstName"
       ng-readonly="memRen" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM