AngularJS: Call the ng-submit event outside the form

前端 未结 10 1478
渐次进展
渐次进展 2020-12-09 02:07

I\'m a fish in AngularJS and I have this scenario.

10条回答
  •  遥遥无期
    2020-12-09 02:18

    Please, surround your code with a ng-controller, and use ng-click on buttons out of scope of

    .

    I make a sample on jsfiddle for you... try it:

    http://jsfiddle.net/xKkvj/2/

    Enter text and hit enter:
    list={{list}}

    with js:

    function Ctrl($scope) {
        $scope.list = [];
        $scope.text = 'hello';
        $scope.submit = function () {
            if ($scope.text) {
                $scope.list.push($scope.text);
                $scope.text = '';
            }
        };
    }
    

提交回复
热议问题