Home >Backend Development >PHP Tutorial >The select bound to angular ng-model cannot be returned?

The select bound to angular ng-model cannot be returned?

WBOY
WBOYOriginal
2016-09-28 08:54:111064browse

I generated a multi-level select through json

<code><div ng-app="xx" ng-controller="eee">
   <div>
                   

 **{{col_selectlv[1].colname}}**//这个地方下文说到!

                    <select ng-model="col_selectlv[0]" ng-options="x.colname for x in col_select[0]" required>

                        <option></option>
                    </select>
                    <select ng-model="col_selectlv[1]" ng-options="x.colname for x in col_selectlv[0].children"
                            ng-if="col_selectlv[0].children"
                            required >
                        <option></option>
                    </select>
                    <select ng-model="col_selectlv[2]" ng-options="x.colname for x in col_selectlv[1].children"
                            ng-if="col_selectlv[1].children" required >
                        <option></option>
                    </select>
                    <select ng-model="col_selectlv[3]" ng-options="x.colname for x in col_selectlv[2].children"
                            ng-if="col_selectlv[2].children" required >
                        <option></option>
                    </select>
                   
                </div>
</div></code>

app.js looks like this:

<code> app.controller('newseditor', function ($scope, $http,$routeParams) {
           $scope.newsid=$routeParams.id?$routeParams.id:'0';
            $http({
                method: 'GET',
                url: 'datacon/col_select.php',

            }).success(function (response) {
                //    console.log(response);
                if (response)
                    $scope.col_select = response;

            })
            $scope.change_selecter = function (r) {
                $scope.select_range = r;
            }
            $scope.news_submit = function () {
                console.log($scope.col_selectlv)

            }
           


        });</code>

Activate news_submit by clicking the button. The desired effect is to output col_selectlv, but the output result is undefined.
ng-model is bound successfully, because the {{col_selectlv[1].colname}} marked above can be output, but I don’t know why it cannot be obtained through $scope.col_selectlv.

Reply content:

I generated a multi-level select through json

<code><div ng-app="xx" ng-controller="eee">
   <div>
                   

 **{{col_selectlv[1].colname}}**//这个地方下文说到!

                    <select ng-model="col_selectlv[0]" ng-options="x.colname for x in col_select[0]" required>

                        <option></option>
                    </select>
                    <select ng-model="col_selectlv[1]" ng-options="x.colname for x in col_selectlv[0].children"
                            ng-if="col_selectlv[0].children"
                            required >
                        <option></option>
                    </select>
                    <select ng-model="col_selectlv[2]" ng-options="x.colname for x in col_selectlv[1].children"
                            ng-if="col_selectlv[1].children" required >
                        <option></option>
                    </select>
                    <select ng-model="col_selectlv[3]" ng-options="x.colname for x in col_selectlv[2].children"
                            ng-if="col_selectlv[2].children" required >
                        <option></option>
                    </select>
                   
                </div>
</div></code>

app.js looks like this:

<code> app.controller('newseditor', function ($scope, $http,$routeParams) {
           $scope.newsid=$routeParams.id?$routeParams.id:'0';
            $http({
                method: 'GET',
                url: 'datacon/col_select.php',

            }).success(function (response) {
                //    console.log(response);
                if (response)
                    $scope.col_select = response;

            })
            $scope.change_selecter = function (r) {
                $scope.select_range = r;
            }
            $scope.news_submit = function () {
                console.log($scope.col_selectlv)

            }
           


        });</code>

Activate news_submit by clicking the button. The desired effect is to output col_selectlv, but the output result is undefined.
ng-model is bound successfully, because the {{col_selectlv[1].colname}} marked above can be output, but I don’t know why it cannot be obtained through $scope.col_selectlv.

Is your controller name eee or newseditor? The code seems incomplete

It turns out that ng-if will create a subdomain, so
app.controller('newseditor', function ($scope, $http,$routeParams) {

<code>        **$scope.col_selectlv={}**
       $scope.newsid=$routeParams.id?$routeParams.id:'0';
        $http({
            method: 'GET',
            url: 'datacon/col_select.php',

        }).success(function (response) {
            //    console.log(response);
            if (response)
                $scope.col_select = response;

        })
        $scope.change_selecter = function (r) {
            $scope.select_range = r;
        }
        $scope.news_submit = function () {
            console.log($scope.col_selectlv)

        }
       
</code>
<code>    });
    要定义一个$scope.col_selectlv,才能够获取到col_selectlv</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn