从角度控制器访问变量

时间:2014-03-20 22:56:11

标签: angularjs angularjs-scope

我有以下代码,

<form role="form" name="form" ng-submit="submit()" novalidate >
            <div class="form-group">
                <label for="inputName">Isminiz</label>
                <input type="text" class="form-control" id="inputName" placeholder="Isminizi yaziniz." ng-model="form.name" required >
            </div>
            <div class="form-group">
                <label for="inputEmail">Email Adresiniz</label>
                <input type="email" class="form-control" id="inputEmail" placeholder="xxx@xxx.xxx" ng-model="form.email" required >
            </div>
            <div class="form-group">
                <label for="inputText">Konu</label>
                <textarea class="form-control" rows="3" id="inputText" placeholder="Lütfen bize iletmek istediğiniz öneri, istek veya görüşlerinizi yazınız."
                          ng-model="form.content" required></textarea>
            </div>
            <button type="submit" id="mail-button" class="btn btn-default" disabled="{{scope.isDisabled}}" ng-disabled="form.$invalid || isUnchanged(user)" data-loading-text="Lütfen bekleyiniz..." data-complete-text="Gönderildi!" data-tekrar-text="Tekrar Deneyin">Gönder</button>
            <div>{{ form.name }}</div>
        </form>

我基本上是尝试访问控制器中的form.x元素,但不知怎的,它无法正常工作。 它们不在范围内吗? 如果需要,我该如何重置这些元素,也是相关的,因为我无法在控制器中找到它们。

2 个答案:

答案 0 :(得分:0)

您可以在控制器中访问这些变量,如:

app.controller('Yourcontroller', function(...){

   $scope.submit = function () {
      var name = $scope.form.name;
      var email = $scope.form.email;
      ...............//Rest of the body
   };
});

答案 1 :(得分:0)

这下面的工作很好,最后。

$scope.form['name']