Angularjs ui tabset范围不更新

时间:2014-01-29 00:12:11

标签: javascript angularjs angular-ui-bootstrap

我正在使用角度ui bootstrap的标签。 一切正常,但我注意到虽然使用ng-model,但是选项卡内的文本框没有更新范围。

我搜索并发现这是因为子范围,并建议在绑定时使用obj.property表示法。

但我的模型仍未更新。

请指导我出错的地方。

wbProcess.controller ("createProCtrl", function ($scope, $http, global, user){

$scope.project = [{protitle :""},
                  {prodesc : ""},
                  {chkarchive : false}
                 ];

$scope.tab = true;

$scope.upurl;

$scope.createpro = function(){
    $http({
        url: global.apiurl+"pro/create",
        method: "POST",
        data: {'name': $scope.project.protitle, 'prodesc': $scope.project.prodesc, 'owner': user.user_id , 'active': $scope.project.chkarchive}
    }).success(function (data, status, headers, config) {
             // assign  $scope.persons here as promise is resolved here
            //$log.log(data);
            if(data.status > 0){
                $scope.tab = false;

                }
            else{

            }
        }).error(function (data, status, headers, config) {
            $scope.status = status;
            $log.log(status);
        });
}


});

HTML

<tabset>
<tab>
    <tab-heading>
        <i class="green icon-edit bigger-110"></i>Description
    </tab-heading>
    <div>
                                <form name="createProForm" class="form-horizontal">

                                    <div class="control-group span7">
                                            <label class="control-label" for="form-field-1">Title</label>

                                        <STYLE type="text/css">
                                               .ng-dirty.ng-valid ~ span.ok { color:green; display:inline; }
                                               .ng-dirty.ng-invalid ~ span.ko { color:red; display:inline; }
                                        </STYLE>

                                        <div class="controls">
                                            <input type="text" name="protitle" id="projecttitle" ng-model="project.protitle" ng-unique="projects" placeholder="Title" required />

                                            <span class="red" ng-show="createProForm.protitle.$error.unique" >
                                                &nbsp;&nbsp;<i class="red icon-asterisk bigger-110"></i>&nbsp;Project Title already exists.</span>
                                            <!--<span class="green" ng-show="createProForm.protitle.$error.unique === false" >
                                                &nbsp;&nbsp;<i class="green icon-asterisk bigger-110"></i>&nbsp;Available</span>
                                            -->
                                        </div>

                                    </div>

                                    <div class="control-group span5">

                                        <div class="controls">
                                            <input class="ace" type="checkbox" id="id-disable-check" ng-model="project.chkarchive"  tabindex="-1"/>
                                            <label class="lbl" for="id-disable-check"> Archive Project</label>
                                        </div>
                                    </div>

                                    <div class="control-group">
                                        <label class="control-label" for="form-field-9">Project Description</label>

                                        <div class="controls">
                                            <textarea class="span7" id="projecttitle" ng-model="project.prodesc" maxlength="100" placeholder="100 Character Limit" required></textarea>
                                        </div>
                                    </div>

                                    <div class="form-actions">
                                        <button class="btn btn-info" type="button" ng-disabled="createProForm.protitle.$pristine || createProForm.protitle.$dirty && createProForm.protitle.$error.unique === true" ng-click="createpro()">
                                            <i class="icon-ok bigger-110"></i>
                                            Save
                                        </button>

                                        &nbsp; &nbsp; &nbsp;
                                        <button class="btn" type="reset">
                                            <i class="icon-undo bigger-110"></i>
                                            Reset
                                        </button>
                                        <button class="btn btn-default btn-sm" ng-click="tabs[1].disabled = ! tabs[1].disabled">Enable / Disable third tab</button>
                                    </div>
                                    </form>
                            </div>
</tab>

<tab disabled = "tab">
    <tab-heading>
        <i class="green icon-cogs bigger-110"></i>Configuration
    </tab-heading>
    <div>
                                <div class="span6">
                                    hi
                                </div>
                                <div id="dropzone" class="span6">
                                    <input type="hidden" id="upurl" value="{{ upurl }}" /> 
                                    <form action="/not-found" class="dropzone">
                                        <div class="fallback">
                                            <input name="file" type="file" multiple/>
                                        </div>
                                    </form>
                                </div>
                            </div>
</tab>

<tab disabled = "tab">
    <tab-heading>
        <i class="green icon-group bigger-110"></i>Users
    </tab-heading>
    <div>
                                <p>Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-table readymade.</p>
                            </div>
</tab>

文本输入仅在第一个标签中。

2 个答案:

答案 0 :(得分:0)

有一种解决方案可以访问它。 您可以使用控制器中的以下语法访问它。 $范围。$$ childHead。$$ nextSibling.yourVariablename。

例如,您在html页面上有ng-model =“state”,您可以像这样访问它

$范围。$$ childHead。$$ nextSibling.state

答案 1 :(得分:0)

由于子范围的原因,在绑定时使用obj.property表示法的建议是正确的,但您错误地将$scope.project定义为对象的列表,而不仅仅是具有多个键的简单对象/值对。

尝试:

$scope.project = {
  protitle: "",
  prodesc : "",
  chkarchive: false
};

另见here