ng-action does not add action attribute in the form

后端 未结 5 1983
醉梦人生
醉梦人生 2020-12-18 20:09

I want to have dynamic action attribute in the form. I have a code

 

Angular d

5条回答
  •  囚心锁ツ
    2020-12-18 20:44

    Here is my solution using Angular directives:

    JS:

    app.controller('formCtrl', ['$scope', function($scope) {
        $scope.customAction = 'http://stackoverflow.com/';
    }])
    .directive('dynamicFormAction', function() {
        return {
            restrict: 'A',
            scope: {
                'dynamicFormAction': '='
            },
            link: function(scope, el, attrs) {
                scope.$watch('dynamicFormAction', function (action) {
                    el[0].action = action;
                });
            }
        };
    });
    

    HTML:

    ...

提交回复
热议问题