1

I have an angular directive:

angular.module("app").directive("myButtons", function () {
    return {
        restrict: "E",
        scope: {
            bdisabled: '='
        },
        templateUrl: "buttons.html"
    }
});

template:

<input type="submit" value="Update" ng-disabled="{{bdisabled}}" />

html:

<my-buttons bdisabled="!form.$valid"></my-buttons>

I'm trying to set the disabled state of the button in my template. The above code almost works.

The form loads and is valid, the html is rendered as follows:

<input type="submit" ng-click="bdisabled()" value="Save" ng-disabled="false" disabled="disabled">

When I make the form invalid ng-disabled changes to true but disabled="disabled" stays no matter what.

What am I doing wrong?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Sun
  • 4,458
  • 14
  • 66
  • 108

3 Answers3

2

since ng-disabled is angular directive no need to use the curly brackets

<input type="submit" value="Update" ng-disabled="bdisabled" />
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80
2

Change ng-disabled="{{bdisabled}}" to ng-disabled="bdisabled",

No need of interpolation operators, as its already in angular scope.

anoop
  • 3,812
  • 2
  • 16
  • 28
2

You can use the variable itself inside the ng-disabled likeng-disabled='disabled' No need of interpolation operator since it is a native angular directive

Prince Gracy
  • 121
  • 4