1

我正在尝试从包含 select(ngOptions) 的表单中解析模型并将其保存到 db 但从未解析过所选值。我被困在这里,有人可以帮忙吗?

这是我的代码:

看法

<section class="container" data-ng-controller="TagsController" >
    <h2><i class="fa fa-pencil-square-o"></i>Add a new Tag</h2>

    <form class="form-horizontal col-md-5" data-ng-submit="create()">
        <div class="form-group ">
            <div class="controls">
                <input type="text" class="form-control input-lg" data-ng-model="label" id="label" placeholder="Label" required>
            </div>
        </div>
        <div class="form-group" data-ng-controller="CategoriesController" data-ng-init="find()">
            <select class="form-control input-lg" ng-model="category._id" ng-options="category._id as category.label for category in categories">
              <option value="">Choose a Category</option>
            </select>
        </div>

        <div class="control-group">
            <div class="controls">
                <input type="submit" class="btn">
            </div>
        </div>

    </form>
</section>

控制器

angular.module('mean.tags').controller('TagsController', ['$scope', '$routeParams', '$location', 'Global', 'Tags', function ($scope, $routeParams, $location, Global, Tags) {
    $scope.global = Global;

    $scope.create = function() {
        var tag = new Tags({
            label: this.label,
            category: this.category
        });
        tag.$save(function(response) {
            $location.path("tags/");
        });
        this.label = "";
        this.category = "";
    };
...
4

1 回答 1

0

我发现了问题,所以我会回答我的问题。问题是由于架构限制,Angularjs 不允许将 ng-controller 嵌套在另一个...

于 2014-01-12T21:19:32.143 回答