Angular Select ng-model不绑定范围

时间:2015-03-09 10:24:17

标签: javascript angularjs

我有以下表格:

    <form role="form" class="form-validation" ng-submit="profilCtrl.saveProfile()">
    <div class="form-group">
        <label class="control-label">Fornavn</label>
        <input type="text" placeholder="John Hansen" class="form-control" ng-model="profile.firstname" name="name" value="{{profilCtrl.profile.firstname}}" required>
    </div>
    <div class="form-group">
        <label class="control-label">Efternavn</label>
        <input type="text" placeholder="John Hansen" class="form-control" ng-model="profile.lastname" name="name" value="{{profilCtrl.profile.lastname}}" required>
    </div>
    <div class="form-group">
        <label class="control-label">Addresse</label>
        <input type="text" placeholder="Mosebakken 12 2830 virum" class="form-control" ng-model="profile.address" name="address" value="{{profilCtrl.profile.address}}" required>
    </div>
    <div class="form-group">
        <label class="control-label">Jobprofil</label>
        <select class="form-control" ng-model="selectedTitle" ng-options="item as item.name for item in titles"></select>
    </div>
    <div class="form-group">
        <label class="control-label">Telefon Number</label>
        <input type="text" placeholder="12345678" class="form-control" name="phone" value="{{profilCtrl.profile.phone}}" required ng-model="profile.phone">
    </div>
    <div class="form-group">
        <label class="control-label">Afdeling</label>
        <select class="form-control" ng-model="selectedDivision" ng-options="division as division.name for division in divisions" required>
        </select>
    </div>
    <div class="form-group">
        <label class="control-label">Fødselsdag</label>
        <input type="text"  placeholder="04-04-1989" class="form-control" name="cpr" ng-model="profile.cpr" value="{{profilCtrl.profile.cpr}}" required>
    </div>
    <div class="form-group">
        <label class="control-label">Vigtig information</label>
        <textarea class="form-control" rows="3" placeholder="Dette er vigtigt for min leder at vide!" name="info" ng-model="profile.description">{{profile.description}}</textarea>
    </div>
    <div class="margiv-top-10">
        <button type="submit" href="#" class="btn green-haze">
            <i class="fa fa-check"></i>
        </button>
    </div>
</form>

此表单中的所有内容都可以使用两个选项:

<select class="form-control" ng-model="selectedTitle" ng-options="item as item.name for item in titles"></select>

<select class="form-control" ng-model="selectedDivision" ng-options="division as division.name for division in divisions" required>

与其他内容不同,这些内容未与profile对象相关联,而应保存在$scope.selectedTitle$scope.selectedDivision

然而,一旦我提交表格,这两个都是未定义的。

任何人都可以告诉我为什么会发生这种情况

0 个答案:

没有答案