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?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-09-28 08:54:11
Original
1086 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
<code>    });
    要定义一个$scope.col_selectlv,才能够获取到col_selectlv</code>
Copy after login
Related labels:
Statement of this Website
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
Latest Issues
angular.js - angularJS ng-style用法
From 1970-01-01 08:00:00
0
0
0
angular.js - AngularJS form validation
From 1970-01-01 08:00:00
0
0
0
angular.js - Learning AngularJS
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template