1

Good Morning! I have a Multiple Autocomplete in AngularJS for show user's skills. I have two tables/variables in php, one with the skills that the user choosed ($cont->personal_skills_cat), and other with a list of Skills ($job_categories). I would like to show the skills that the client have in the Multiple Autocomplete, and can to add or remove, from a list of suggestions ($job_categories). It is my code for now. Thanks.

Note: It is in Laravel, so the Blade variables are in {{}} and the AngularJS variables are in <% %>

<label>Jobs Categories</label><br>
        <?
        $personal_skills_cat = $jobs_categories;
        $per_skills_cat = json_encode($personal_skills_cat);

        $per_skills_cats = $cont->personal_skills_cat;

        $per_skills_cats = json_decode($per_skills_cats);
        if(isset($per_skills_cats)):
        foreach ($per_skills_cats as $key => $skill_cat): ?>
            <span class="tag">{{$skill_cat->name}}</span>
        <? endforeach;endif;?>
        <br/><br/>

        <multiple-autocomplete id="skills_cat"
                               name="skills_cat"
                               ng-model="skillsFromApi"
                               css-class="someClass"
                               object-property="name"
                               suggestions-arr="{{$per_skills_cat}}">
        </multiple-autocomplete> 
        <input type="hidden" name="skills_cat" value="<%skillsFromApi%>">
2
  • did you manage to find solution to your question? Commented Apr 3, 2017 at 21:36
  • No, I used Jquery finally. However, I would like to find a solution for this. Thanks. Commented Apr 4, 2017 at 7:02

1 Answer 1

1

I've tried to perserve your original idea in the code, but I had to change few lines since there were errors. Also I don't have the access to your data so I had to improvise on that part.

PersonalSkillsController

var myApp = angular.module('myApp', ['multipleSelect']).config(function($interpolateProvider){
    $interpolateProvider.startSymbol('<%').endSymbol('%>');
});

myApp.controller('PersonalSkillsController', ['$scope', function($scope){

    $scope.optionsList = [
        "Java",
        "C",
        "C++",
        "AngularJs",
        "JavaScript"
    ];

    $scope.selectedList = [];

    $scope.setSelectedList = function(list) {
        $scope.selectedList = list;
    };
}]);

PHP file

<body>

<?php
    $jobs_categories = ["Java","C"];
    $per_skills_cats = json_encode($jobs_categories);
?>

<div ng-controller="PersonalSkillsController" ng-init='setSelectedList(<?php echo $per_skills_cats; ?>)'>
    <multiple-autocomplete
            ng-model="selectedList"
            suggestions-arr="optionsList"></multiple-autocomplete>
</div>
</body>
Sign up to request clarification or add additional context in comments.

2 Comments

Mmm, interesting. Thanks for this.
if it's the correct solution you could accept the answer. or post here if there is some kind of error in the code. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.