mercredi 8 août 2018

Template for directive 'selectUser' must have exactly one root element

i am using a directive select-user in multiple places , and its all working fine. but the issue when i add a new html element place in directive html template.neither work in if i am using in div element.

always error return "Template for directive 'selectUser' must have exactly one root element"

i have to add a checkbox and change the want to change data source based on check box value.

directive calling in this way

i have a directive code in js file

App.directive('selectUser', ['$http', '$timeout', '$rootScope', function ($http, $timeout, $rootScope) {
    return {
        restrict: 'E',
        require: 'ngModel',
        templateUrl: 'app/shared/partial/userlist.html',
        replace: true,
        scope: {
            isDisabled: '=?', // optional                     

        },
        link: function (scope, element, attr, ngModelCtrl) {
            scope.$watch('isDisabled', function (newVal) {
                scope.accessDisabled = newVal;

                if (newVal == undefined || newVal == null) {
                    scope.accessDisabled = false;
                }
            });

            scope.LoadUsers = function () {

                scope.teamUsers = response;//data from API.

        }
        }
    };
}]);

userlist.html

 <select id="teamUsers" data-placeholder="Select User" chosen="" class="chosen-select input-md"
            ng-options="user.EncryptedID as user.EmployeeName+' '+user.EmployeeLastName+', '+user.TeamName  for user in teamUsers"
            ng-disabled="accessDisabled">
        <option disabled></option>

    </select>

-- Error




Aucun commentaire:

Enregistrer un commentaire