add class to two different button in x-editable angular - html

here I want to add two different class to two button using x-editable angular.
<div ng-app="app" ng-controller="Ctrl">
<div>Email: {{ user.email || 'empty' }}</div>
</div>

you need to configure for all the buttons at once like so
app.run(function(editableOptions, editableThemes) {
editableOptions.theme = 'bs3';
editableThemes.bs3.buttonsClass = 'class1';
});
var app = angular.module("app", ["xeditable"]);
app.run(function(editableOptions, editableThemes) {
editableOptions.theme = 'bs3';
editableThemes.bs3.buttonsClass = 'class1';
});
app.controller('Ctrl', function($scope) {
$scope.user = {
name: 'awesome user'
};
});
div[ng-app] {
margin: 50px;
}
.class1 {
color: green !important;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<link href="http://vitalets.github.io/angular-xeditable/dist/css/xeditable.css" rel="stylesheet" />
<script src="http://vitalets.github.io/angular-xeditable/dist/js/xeditable.js"></script>
<h4>Angular-xeditable Customize input (Bootstrap 3)</h4>
<div ng-app="app" ng-controller="Ctrl">
<a href="#" editable-text="user.name" e-required e-placeholder="Enter name" e-class="class1 class2">
{{ (user.name || 'empty') | uppercase }}
</a>
</div>

Related

want to directly add class to input element when click on editable fields in x-editable angular

here I am using Angular x-editable. I want to add the class directly to the input element and buttons
<div ng-app="app" ng-controller="Ctrl">
<div>Email: {{ user.email || 'empty' }}</div>
</div>
How about using e-class="class1 class2" refer here
var app = angular.module("app", ["xeditable"]);
app.run(function(editableOptions) {
editableOptions.theme = 'bs3';
});
app.controller('Ctrl', function($scope) {
$scope.user = {
name: 'awesome user'
};
});
div[ng-app] {
margin: 50px;
}
.class1 {
color: green !important;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<link href="http://vitalets.github.io/angular-xeditable/dist/css/xeditable.css" rel="stylesheet"/>
<script src="http://vitalets.github.io/angular-xeditable/dist/js/xeditable.js"></script>
<h4>Angular-xeditable Customize input (Bootstrap 3)</h4>
<div ng-app="app" ng-controller="Ctrl">
<a href="#" editable-text="user.name" e-required e-placeholder="Enter name" e-class="class1 class2">
{{ (user.name || 'empty') | uppercase }}
</a>
</div>

Where to initialize jquery for laravel

I am trying to add the drag and drop functionality to my fancy tree. However, there seem to be an issue with where i am initializing the jquery library resulting in error messages indicating that the jquery function i am trying to use is not available etc.
Specific error message = app.js:24 jQuery.Deferred exception: $(...).perfectScrollbar is not a function TypeError: $(...).perfectScrollbar is not a function
If i were to directly initialize a perfect scroll bar, it will continue reflecting other libraries are not a function etc
Simplistic overview of code (Edited to show that master blade is already requiring jquery once)
--Master Blade--
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}" #if (config('voyager.multilingual.rtl')) dir="rtl" #endif>
<head>
<title>#yield('page_title', setting('admin.title') . " - " . setting('admin.description'))</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}"/>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700" rel="stylesheet">
<!-- Favicon -->
<link rel="shortcut icon" href="{{ voyager_asset('images/logo-icon.png') }}" type="image/x-icon">
<!-- App CSS -->
<link rel="stylesheet" href="{{ voyager_asset('css/app.css') }}">
<!-- fancy tree jquery/css-->
#yield('css')
#if(config('voyager.multilingual.rtl'))
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-rtl/3.4.0/css/bootstrap-rtl.css">
<link rel="stylesheet" href="{{ voyager_asset('css/rtl.css') }}">
#endif
<!-- Few Dynamic Styles -->
<style type="text/css">
.voyager .side-menu .navbar-header {
background:#FFFFFF;
border-color:#FFFFFF;
{{--background:{{ config('voyager.primary_color','#22A7F0') }};--}}
{{--border-color:{{ config('voyager.primary_color','#22A7F0') }};--}}
}
.widget .btn-primary{
border-color:{{ config('voyager.primary_color','#22A7F0') }};
}
.widget .btn-primary:focus, .widget .btn-primary:hover, .widget .btn-primary:active, .widget .btn-primary.active, .widget .btn-primary:active:focus{
background:{{ config('voyager.primary_color','#22A7F0') }};
}
.voyager .breadcrumb a{
color:{{ config('voyager.primary_color','#22A7F0') }};
}
.app-container .side-menu .panel.widget h5 {
float: left;
display: block;
position: absolute;
top: 0px;
width: 180px;
text-align: left;
opacity: 0;
transition: opacity .3s ease;
margin-top: 17px;
left: 68px;
overflow: hidden;
height: 29px;
}
.app-container .side-menu .panel.widget h6 {
float: left;
display: block;
position: absolute;
top: 15px;
width: 180px;
text-align: left;
opacity: 0;
transition: opacity .3s ease;
margin-top: 17px;
left: 68px;
overflow: hidden;
height: 29px;
}
.app-container.expanded .panel.widget h5 {
opacity: 1;
}
.app-container.expanded .panel.widget h6 {
opacity: 1;
}
.app-container .side-menu:hover .panel.widget h5 {
opacity: 1;
}
.app-container .side-menu:hover .panel.widget h6 {
opacity: 1;
}
</style>
#if(!empty(config('voyager.additional_css')))<!-- Additional CSS -->
#foreach(config('voyager.additional_css') as $css)<link rel="stylesheet" type="text/css" href="{{ asset($css) }}">#endforeach
#endif
#yield('head')
</head>
<body class="voyager #if(isset($dataType) && isset($dataType->slug)){{ $dataType->slug }}#endif">
<div id="voyager-loader">
<?php $admin_loader_img = Voyager::setting('admin.loader', ''); ?>
#if($admin_loader_img == '')
<img src="{{ voyager_asset('images/logo-icon.png') }}" alt="Voyager Loader">
#else
<img src="{{ Voyager::image($admin_loader_img) }}" alt="Voyager Loader">
#endif
</div>
<?php
if (starts_with(Auth::user()->avatar, 'http://') || starts_with(Auth::user()->avatar, 'https://')) {
$user_avatar = Auth::user()->avatar;
} else {
$user_avatar = Voyager::image(Auth::user()->avatar);
}
?>
<div class="app-container">
<div class="fadetoblack visible-xs"></div>
<div class="row content-container">
#include('voyager::dashboard.navbar')
#include('voyager::dashboard.sidebar')
<script>
(function(){
var appContainer = document.querySelector('.app-container'),
sidebar = appContainer.querySelector('.side-menu'),
navbar = appContainer.querySelector('nav.navbar.navbar-top'),
loader = document.getElementById('voyager-loader'),
hamburgerMenu = document.querySelector('.hamburger'),
sidebarTransition = sidebar.style.transition,
navbarTransition = navbar.style.transition,
containerTransition = appContainer.style.transition;
sidebar.style.WebkitTransition = sidebar.style.MozTransition = sidebar.style.transition =
appContainer.style.WebkitTransition = appContainer.style.MozTransition = appContainer.style.transition =
navbar.style.WebkitTransition = navbar.style.MozTransition = navbar.style.transition = 'none';
if (window.localStorage && window.localStorage['voyager.stickySidebar'] == 'true') {
appContainer.className += ' expanded no-animation';
loader.style.left = (sidebar.clientWidth/2)+'px';
hamburgerMenu.className += ' is-active no-animation';
}
navbar.style.WebkitTransition = navbar.style.MozTransition = navbar.style.transition = navbarTransition;
sidebar.style.WebkitTransition = sidebar.style.MozTransition = sidebar.style.transition = sidebarTransition;
appContainer.style.WebkitTransition = appContainer.style.MozTransition = appContainer.style.transition = containerTransition;
})();
</script>
<!-- Main Content -->
<div class="container-fluid">
<div class="side-body padding-top">
#yield('page_header')
<div id="voyager-notifications"></div>
#yield('content')
</div>
</div>
</div>
</div>
#include('voyager::partials.app-footer')
<!-- Javascript Libs -->
<script type="text/javascript" src="{{ voyager_asset('js/app.js') }}"></script>
<!-- <script type="text/javascript" src="{{ voyager_asset('js/app.js') }}"></script> -->
<script>
#if(Session::has('alerts'))
let alerts = {!! json_encode(Session::get('alerts')) !!};
helpers.displayAlerts(alerts, toastr);
#endif
#if(Session::has('message'))
// TODO: change Controllers to use AlertsMessages trait... then remove this
var alertType = {!! json_encode(Session::get('alert-type', 'info')) !!};
var alertMessage = {!! json_encode(Session::get('message')) !!};
var alerter = toastr[alertType];
if (alerter) {
alerter(alertMessage);
} else {
toastr.error("toastr alert-type " + alertType + " is unknown");
}
#endif
</script>
#yield('javascript')
<!-- Javascript Libs -->
<!-- <script type="text/javascript" src="{{ voyager_asset('js/app.js') }}"></script> -->
#if(!empty(config('voyager.additional_js')))<!-- Additional Javascript -->
#foreach(config('voyager.additional_js') as $js)<script type="text/javascript" src="{{ asset($js) }}"></script>#endforeach
#endif
</body>
</html>
--Fancy Tree Blade --
Extends Master Blade
#section('content')
--fancy tree code--
#stop
#section('javascript)
<script src="//code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="/src/jquery-ui-dependencies/jquery.fancytree.ui-deps.js" type="text/javascript"></script>
<script src="/src/jquery.fancytree.js" type="text/javascript"></script>
<script src="/src/jquery.fancytree.dnd.js" type="text/javascript"></script>
<script src="/src/jquery.fancytree.edit.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
// using default options
$("#tree").fancytree({
extensions: ["dnd"],
checkbox: false,
icon: false,
generateIds: true,
dnd: {
autoExpandMS: 400,
focusOnClick: true,
preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
preventRecursiveMoves: true, // Prevent dropping nodes on own descendants
dragStart: function(node, data) {
/** This function MUST be defined to enable dragging for the tree.
* Return false to cancel dragging of node.
*/
return true;
},
dragEnter: function(node, data) {
/** data.otherNode may be null for non-fancytree droppables.
* Return false to disallow dropping on node. In this case
* dragOver and dragLeave are not called.
* Return 'over', 'before, or 'after' to force a hitMode.
* Return ['before', 'after'] to restrict available hitModes.
* Any other return value will calc the hitMode from the cursor position.
*/
// Prevent dropping a parent below another parent (only sort
// nodes under the same parent)
/* if(node.parent !== data.otherNode.parent){
return false;
}
// Don't allow dropping *over* a node (would create a child)
return ["before", "after"];
*/
return true;
},
dragDrop: function(node, data) {
/** This function MUST be defined to enable dropping of items on
* the tree.
*/
data.otherNode.moveTo(node, data.hitMode);
}
},
}
Most of the time getting this error
TypeError: $(…).perfectScrollbar is not a function
Is because of the wrong Order of scripts and sometimes it is because of jQuery enabled version. in the master.blade, page bring the #yield('javascript') right after calling #include('voyager::partials.app-footer') and make sure there isn't any js file in #include('voyager::partials.app-footer') if there it will cause the same error again so take out the js file and import it in your master.blade file.
Try this
I am trying to add the drag and drop functionality to my fancy tree. However, there seem to be an issue with where i am initializing the jquery library resulting in error messages indicating that the jquery function i am trying to use is not available etc.
Specific error message = app.js:24 jQuery.Deferred exception: $(...).perfectScrollbar is not a function TypeError: $(...).perfectScrollbar is not a function
If i were to directly initialize a perfect scroll bar, it will continue reflecting other libraries are not a function etc
Simplistic overview of code (Edited to show that master blade is already requiring jquery once)
--Master Blade--
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}" #if (config('voyager.multilingual.rtl')) dir="rtl" #endif>
<head>
<title>#yield('page_title', setting('admin.title') . " - " . setting('admin.description'))</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}"/>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700" rel="stylesheet">
<!-- Favicon -->
<link rel="shortcut icon" href="{{ voyager_asset('images/logo-icon.png') }}" type="image/x-icon">
<!-- App CSS -->
<link rel="stylesheet" href="{{ voyager_asset('css/app.css') }}">
<!-- fancy tree jquery/css-->
#yield('css')
#if(config('voyager.multilingual.rtl'))
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-rtl/3.4.0/css/bootstrap-rtl.css">
<link rel="stylesheet" href="{{ voyager_asset('css/rtl.css') }}">
#endif
<!-- Few Dynamic Styles -->
<style type="text/css">
.voyager .side-menu .navbar-header {
background:#FFFFFF;
border-color:#FFFFFF;
{{--background:{{ config('voyager.primary_color','#22A7F0') }};--}}
{{--border-color:{{ config('voyager.primary_color','#22A7F0') }};--}}
}
.widget .btn-primary{
border-color:{{ config('voyager.primary_color','#22A7F0') }};
}
.widget .btn-primary:focus, .widget .btn-primary:hover, .widget .btn-primary:active, .widget .btn-primary.active, .widget .btn-primary:active:focus{
background:{{ config('voyager.primary_color','#22A7F0') }};
}
.voyager .breadcrumb a{
color:{{ config('voyager.primary_color','#22A7F0') }};
}
.app-container .side-menu .panel.widget h5 {
float: left;
display: block;
position: absolute;
top: 0px;
width: 180px;
text-align: left;
opacity: 0;
transition: opacity .3s ease;
margin-top: 17px;
left: 68px;
overflow: hidden;
height: 29px;
}
.app-container .side-menu .panel.widget h6 {
float: left;
display: block;
position: absolute;
top: 15px;
width: 180px;
text-align: left;
opacity: 0;
transition: opacity .3s ease;
margin-top: 17px;
left: 68px;
overflow: hidden;
height: 29px;
}
.app-container.expanded .panel.widget h5 {
opacity: 1;
}
.app-container.expanded .panel.widget h6 {
opacity: 1;
}
.app-container .side-menu:hover .panel.widget h5 {
opacity: 1;
}
.app-container .side-menu:hover .panel.widget h6 {
opacity: 1;
}
</style>
#if(!empty(config('voyager.additional_css')))<!-- Additional CSS -->
#foreach(config('voyager.additional_css') as $css)<link rel="stylesheet" type="text/css" href="{{ asset($css) }}">#endforeach
#endif
#yield('head')
</head>
<body class="voyager #if(isset($dataType) && isset($dataType->slug)){{ $dataType->slug }}#endif">
<div id="voyager-loader">
<?php $admin_loader_img = Voyager::setting('admin.loader', ''); ?>
#if($admin_loader_img == '')
<img src="{{ voyager_asset('images/logo-icon.png') }}" alt="Voyager Loader">
#else
<img src="{{ Voyager::image($admin_loader_img) }}" alt="Voyager Loader">
#endif
</div>
<?php
if (starts_with(Auth::user()->avatar, 'http://') || starts_with(Auth::user()->avatar, 'https://')) {
$user_avatar = Auth::user()->avatar;
} else {
$user_avatar = Voyager::image(Auth::user()->avatar);
}
?>
<div class="app-container">
<div class="fadetoblack visible-xs"></div>
<div class="row content-container">
#include('voyager::dashboard.navbar')
#include('voyager::dashboard.sidebar')
<script>
(function(){
var appContainer = document.querySelector('.app-container'),
sidebar = appContainer.querySelector('.side-menu'),
navbar = appContainer.querySelector('nav.navbar.navbar-top'),
loader = document.getElementById('voyager-loader'),
hamburgerMenu = document.querySelector('.hamburger'),
sidebarTransition = sidebar.style.transition,
navbarTransition = navbar.style.transition,
containerTransition = appContainer.style.transition;
sidebar.style.WebkitTransition = sidebar.style.MozTransition = sidebar.style.transition =
appContainer.style.WebkitTransition = appContainer.style.MozTransition = appContainer.style.transition =
navbar.style.WebkitTransition = navbar.style.MozTransition = navbar.style.transition = 'none';
if (window.localStorage && window.localStorage['voyager.stickySidebar'] == 'true') {
appContainer.className += ' expanded no-animation';
loader.style.left = (sidebar.clientWidth/2)+'px';
hamburgerMenu.className += ' is-active no-animation';
}
navbar.style.WebkitTransition = navbar.style.MozTransition = navbar.style.transition = navbarTransition;
sidebar.style.WebkitTransition = sidebar.style.MozTransition = sidebar.style.transition = sidebarTransition;
appContainer.style.WebkitTransition = appContainer.style.MozTransition = appContainer.style.transition = containerTransition;
})();
</script>
<!-- Main Content -->
<div class="container-fluid">
<div class="side-body padding-top">
#yield('page_header')
<div id="voyager-notifications"></div>
#yield('content')
</div>
</div>
</div>
</div>
#include('voyager::partials.app-footer')
#yield('javascript')
<!-- Javascript Libs -->
<script type="text/javascript" src="{{ voyager_asset('js/app.js') }}"></script>
<!-- <script type="text/javascript" src="{{ voyager_asset('js/app.js') }}"></script> -->
<script>
#if(Session::has('alerts'))
let alerts = {!! json_encode(Session::get('alerts')) !!};
helpers.displayAlerts(alerts, toastr);
#endif
#if(Session::has('message'))
// TODO: change Controllers to use AlertsMessages trait... then remove this
var alertType = {!! json_encode(Session::get('alert-type', 'info')) !!};
var alertMessage = {!! json_encode(Session::get('message')) !!};
var alerter = toastr[alertType];
if (alerter) {
alerter(alertMessage);
} else {
toastr.error("toastr alert-type " + alertType + " is unknown");
}
#endif
</script>
<!-- Javascript Libs -->
<!-- <script type="text/javascript" src="{{ voyager_asset('js/app.js') }}"></script> -->
#if(!empty(config('voyager.additional_js')))<!-- Additional Javascript -->
#foreach(config('voyager.additional_js') as $js)<script type="text/javascript" src="{{ asset($js) }}"></script>#endforeach
#endif
</body>
</html>
--Fancy Tree Blade --
Extends Master Blade
#section('content')
--fancy tree code--
#stop
#section('javascript)
<script type="text/javascript">
$(function(){
// using default options
$("#tree").fancytree({
extensions: ["dnd"],
checkbox: false,
icon: false,
generateIds: true,
dnd: {
autoExpandMS: 400,
focusOnClick: true,
preventVoidMoves: true, // Prevent dropping nodes 'before self', etc.
preventRecursiveMoves: true, // Prevent dropping nodes on own descendants
dragStart: function(node, data) {
/** This function MUST be defined to enable dragging for the tree.
* Return false to cancel dragging of node.
*/
return true;
},
dragEnter: function(node, data) {
/** data.otherNode may be null for non-fancytree droppables.
* Return false to disallow dropping on node. In this case
* dragOver and dragLeave are not called.
* Return 'over', 'before, or 'after' to force a hitMode.
* Return ['before', 'after'] to restrict available hitModes.
* Any other return value will calc the hitMode from the cursor position.
*/
// Prevent dropping a parent below another parent (only sort
// nodes under the same parent)
/* if(node.parent !== data.otherNode.parent){
return false;
}
// Don't allow dropping *over* a node (would create a child)
return ["before", "after"];
*/
return true;
},
dragDrop: function(node, data) {
/** This function MUST be defined to enable dropping of items on
* the tree.
*/
data.otherNode.moveTo(node, data.hitMode);
}
},
}
<script src="//code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="/src/jquery-ui-dependencies/jquery.fancytree.ui-deps.js" type="text/javascript"></script>
<script src="/src/jquery.fancytree.js" type="text/javascript"></script>
<script src="/src/jquery.fancytree.dnd.js" type="text/javascript"></script>
<script src="/src/jquery.fancytree.edit.js" type="text/javascript"></script>

How to add spaces between different tags

I have some code that looks like this
<div class="topnav">
<div>{{getGameView.Game.gameplayers[0].player.username}}</div>
<p>VS</p>
<div v-if="getGameView.Game.gameplayers.length > 1">
  {{getGameView.Game.gameplayers[1].player.username}}
 </div>
<div v-else>Waiting for opponent...</div>
</div>
Which prints this: NameVSName
I am trying to make it so that between Name and VS there is some space but cannot figure out how to do it.
A solution is to give to the VS element a class like .vs and add some padding to it:
p {
margin: 0;
}
.topnav {
display: flex;
}
.topnav .vs {
padding-right: 10px;
padding-left: 10px;
}
<div class="topnav">
<div>Name</div>
<p class="vs">VS</p>
<div>Name</div>
</div>
You can insert a space in html with .
Vue.config.devtools = false;
Vue.config.productionTip = false;
var app = new Vue({
el: '#app',
data: {
nameA: "Job",
nameB: "Bob"
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
{{ nameA }} Vs {{ nameB }}
</div>
How to insert spaces/tabs in text using HTML/CSS

HTML View doesn't display updated model

I have an HTML file which displays 2 lists using AngularJS file with 2 controllers and a service. The lists are arrays which are being correctly updated in the model, as evidenced by the console.log output. But the HTML doesn't display the updated list2 (data stored in the angularJS service). Can someone tell where I am going wrong?
Tried looking at the API, angular directives, Controller As syntax and inheritance concepts.
index.html
<!DOCTYPE html>
<html lang="en" ng-app="ShoppingListCheckOff">
<head>
<title>Shopping List Check Off</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="styles/bootstrap.min.css" />
<script src="angular.min.js"></script>
<script src="app.js"></script>
<style>
.emptyMessage {
font-weight: bold;
color: red;
font-size: 1.2em;
}
li {
margin-bottom: 7px;
font-size: 1.2em;
}
li > button {
margin-left: 6px;
}
button > span {
color: green;
}
</style>
</head>
<body>
<div class="container">
<h1>Shopping List Check Off</h1>
<div class="row">
<!-- To Buy List -->
<div class="col-md-6" ng-controller="ToBuyController as toBuy">
<h2>To Buy:</h2>
<ul>
<li ng-repeat="item in toBuy.list">
Buy {{ item.name }} {{ item.quantity }}
<button ng-click="toBuy.bought($index)" class="btn btn-default">
<span class="glyphicon glyphicon-ok"></span> Bought
</button>
</li>
</ul>
<div ng-if="!toBuy.list.length" class="emptyMessage">Everything is bought!</div>
</div>
<!-- Already Bought List -->
<div class="col-md-6">
<h2>Already Bought:</h2>
<ul>
<li ng-repeat="item in bought.list">Bought {{ item.quantity }} {{ item.name }}</li>
</ul>
<div ng-if="!bought.list.length" class="emptyMessage">Nothing bought yet.</div>
</div>
</div>
</div>
</body>
</html>
App.js
(function() {
'use strict';
angular
.module('ShoppingListCheckOff', [])
.controller('ToBuyController', ToBuyController)
.controller('AlreadyBoughtController', AlreadyBoughtController)
.service('ShoppingListCheckOffService', ShoppingListCheckOffService);
ToBuyController.$inject = ['ShoppingListCheckOffService'];
function ToBuyController(ShoppingListCheckOffService) {
var toBuy = this;
toBuy.list = ShoppingListCheckOffService.getList(1);
toBuy.bought = function(itemIndex) {
ShoppingListCheckOffService.transfer(itemIndex);
};
}
AlreadyBoughtController.$inject = ['ShoppingListCheckOffService'];
function AlreadyBoughtController(ShoppingListCheckOffService) {
var bought = this;
bought.list = ShoppingListCheckOffService.getList(2);
}
function ShoppingListCheckOffService() {
var service = this;
// List of shopping items
var list1 = [
{ name: 'Cookies', quantity: 10 },
{ name: 'Bananas', quantity: 100 },
{ name: 'Toys', quantity: 6 },
{ name: 'Dildos', quantity: 300 },
{ name: 'Yaakovs', quantity: 1 }
];
var list2 = [];
service.transfer = function(itemIndex) {
list2 = list2.concat(list1.splice(itemIndex, 1));
console.log('List 1', list1);
console.log('List 2', list2);
};
service.getList = function(num) {
if (num == 1) {
return list1;
}
if (num == 2) {
return list2;
}
};
}
})();
The issue is that concat does not change the original array. It creates a new array. When you do list2 = list2.concat(list1.splice(itemIndex, 1)); you are setting list2 to a new array but bought.list is still set to the old array so it doesn't change.
One solution would be to
replace
list2 = list2.concat(list1.splice(itemIndex, 1));
with
list2.push(list1.splice(itemIndex, 1)[0]);

manually replicate bootstraps typehead-show-hint with angular, css, html

Is there a away to replicate bootstraps typehead suggestive hint feature only using angular, html and css. I would like to show the first item of the search results dynamically in the search box!
<body>
<div ng-app="demoApp" ng-controller='demoCtrl'>
<br>
<input type="text" ng-model="search_term" placeholder="search...">
<br>
<div ng-repeat="(index, item) in items | filter:search_term" ng-class="{'is-first' : index == 0}">{{item}}</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script>
var app = angular.module('demoApp', []);
app.controller('demoCtrl', ['$scope', function($scope) {
$scope.items = [
'Apple',
'Apricot',
'Avocado',
'Banana',
'Bilberry',
'Blackberry',
'Blackcurrant',
'Blueberry',
'Boysenberry',
'Cantaloupe',
'Currant',
'Cherry',
'Cherimoya',
'Cloudberry',
'Coconut',
'Cranberry',
'Damson',
'Date',
'Dragonfruit'
];
}]);
</script>
<style>
/* put any CSS you need here */
.is-first {
color:red;
}
</style>
</body>
Any help appreciated!
My solution in the end, I used ng-change to hide/show a duplicate input box which returned the first item on the search filter:
<body>
<div ng-app="demoApp" ng-controller='demoCtrl'>
<br>
<input class="main" type="text" ng-model="search_term" placeholder="search..." ng-change="showSuggest()">
<br>
<div ng-show="suggestion" class="autocomplete" ng-repeat="(index, item) in items | filter:search_term | limitTo:1">
<input disabled type="text" placeholder=" {{ item }}">
</div>
<div ng-repeat="(index, item) in items | filter:search_term" ng-class="{'is-first' : index == 0}">{{item}}</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script>
var app = angular.module('demoApp', []);
app.controller('demoCtrl', ['$scope', function($scope) {
$scope.suggestion = false;
$scope.items = [
'Apple',
'Apricot',
'Avocado',
'Banana',
'Bilberry',
'Blackberry',
'Blackcurrant',
'Blueberry',
'Boysenberry',
'Cantaloupe',
'Currant',
'Cherry',
'Cherimoya',
'Cloudberry',
'Coconut',
'Cranberry',
'Damson',
'Date',
'Dragonfruit'
];
$scope.showSuggest = function(){
if ($scope.search_term.length < 1)
{$scope.suggestion = false}
else {$scope.suggestion = true}
};
}]);
</script>
<style>
/* put any CSS you need here */
.is-first {
color:red;
}
.main{
position: absolute;
top: 10;
left: 10;
z-index: 11;
background: transparent;
}
.autocomplete{
position: absolute;
top: 10;
left: 10;
background: transparent;
z-index: 10;
}
</style>