- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图“重载”我应用程序中的所有输入。在这样做的过程中,我还希望根据指令范围内的标志使用 ngDisabled。
这是我得到的,我被卡住的地方是让 ng-disabled 在元素上工作。我猜我需要在修改后重新编译元素或其他东西吗?我还使用对象表示法调用指令:
angular.module("MimosaApp").directive({
"textarea": appInputs,
"input": appInputs
});
var appInputs = function($compile, Device) {
return {
restrict: 'E',
require: '?ngModel',
priority: 101,
template: function(tElement, tAttrs) {
tElement.attr("ng-disabled", 'isDisabled');
return tElement;
},
link: function($scope, element, attrs) {
$compile(element);
element.on("focus", function() {
console.log($scope);
})
},
controller: function($scope, $element) {
$scope.isDisabled = true;
console.log($scope);
}
}
};
我看到的是...即使我在范围内将 isDisabled 设置为 true,也没有禁用任何东西。我错过了什么?
好的,也许我确实需要澄清一下。当用户与某种输入交互时,我目前有一条消息被发送回服务器,然后发送给所有其他连接的客户端。这样,用户的 View 会根据另一个用户的交互而改变。
为了更好地利用 Angular,我正在考虑尝试使用 angular ngDisabled 指令。当用户聚焦某个元素时,其他用户会看到该元素被禁用。
我目前跟踪服务器上的“全局”UI 状态,并将此 JSON 对象发送到客户端,然后客户端自行更新。所以我希望根据范围标志(或其他行为)禁用元素(或其他 CSS 类)。类似于 $scope.fieldsDisabled[fieldName]
并将其设置为 true/false。
也许我通过指令方式考虑错误。
这有意义吗?哈哈
最佳答案
在指令生命周期中,template
函数在编译之前被调用,因此理想情况下它应该可以正常工作,因为您是在模板函数中设置属性。您可以尝试更改编译函数中的属性吗?像这样。
var appInputs = function($compile, Device) {
return {
restrict: 'E',
require: '?ngModel',
priority: 101,
compile: function(tElement, tAttrs) {
tElement.attr("ng-disabled", 'isDisabled');
return function($scope, element, attrs) {
element.on("focus", function() {
console.log($scope);
});
}
},
controller: function($scope, $element) {
$scope.isDisabled = true;
console.log($scope);
}
}
};
关于angularjs - 在指令中添加 ngDisabled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30718745/
我试图“重载”我应用程序中的所有输入。在这样做的过程中,我还希望根据指令范围内的标志使用 ngDisabled。 这是我得到的,我被卡住的地方是让 ng-disabled 在元素上工作。我猜我需要在修
在AnguarJS中,是否有与ngDisabled相反的指令?所以不要写: ... 我会写: ... 最佳答案 HTML specifies disabled 属性(但不是 enabled 属
因此,如果未填写必填字段,我首先要求禁用提交按钮。 Submit 到目前为止一切顺利。但是,如果有如下所示的附加验证字段,则上述内容将不起作用,因为要求仅在未填写必填字段的情况下禁
我有一个简单的表单,用于在 MailChimp 列表中注册信息。如果输入字段尚未填写,我想禁用“提交”按钮。
如果字段不正确,我想阻止用户单击“注册”按钮。部分原因是必须填写某些字段。但条件开始变得有点长: Register 我怎样才能简化它? 最佳答案 我想你需要的是提供required表单中输入字段的属性
当我使用 type="date" 设置输入值时,AngularJS 将不知道元素是否具有值。下面是我的示例代码。 A disabled button Set Value
我有一个 DOM 按钮,当没有用户选择时它被禁用(它在加载时设置为 false)但是,我还需要在数组为空时禁用此按钮。例如,我有一组组,当所有组都已添加后,我想禁用添加按钮。
我正在为我的 CSS 使用 Foundation,它为 form style 使用 fieldset .因此,我不能在我的表单上使用它来在某些情况下禁用我的表单,而不会覆盖它的所有 CSS(我实际上出
我正在使用 API 通过 $http 填充 $scope.var,并采用该 $scope.var。 我有一个嵌套的ng-repeat html: {{chore}}
我是一名优秀的程序员,十分优秀!