Answer the question
In order to leave comments, you need to log in
What is the difference between $scope and this?
I'm trying to figure out with ui-sortable .
A not very clear situation arose: I study Angular at codeschool, where this is used everywhere, and in Google I always come across $scope.
Why with this code:
html:
<body ng-controller="TestSortableController as SortCtrl">
<ul id="list_1" class="list_1" ui-sortable="list1Options" ng-model="SortCtrl.list1">
<li class="app" ng-repeat="app in SortCtrl.list1"> {{ app.name }} </li>
</ul>
<ul id="list_2" class="list_2" ui-sortable="list2Options" ng-model="SortCtrl.list2">
<li class="app" ng-repeat="app in SortCtrl.list2"> {{ app.name }} </li>
</ul>
</body>
(function () {
var app = angular.module('testSortable', ['ui.sortable']);
app.controller('TestSortableController', function () {
this.list1 = [
{
name: "first name",
type: "second type"
}, {
name: "second name",
type: "third type"
}
];
this.list2 = [
{
name: "another name",
type: "another type"
},{
name: "another second name",
type: "another second type"
},
];
this.list1Options = {
placeholder: 'app',
connectWith: '.list_2'
};
this.list2Options = {};
});
})();
<body ng-controller="TestSortableController">
<ul id="list_1" class="list_1" ui-sortable="list1Options" ng-model="list1">
<li class="app" ng-repeat="app in list1"> {{ app.name }} </li>
</ul>
<ul id="list_2" class="list_2" ui-sortable="list2Options" ng-model="list2">
<li class="app" ng-repeat="app in list2"> {{ app.name }} </li>
</ul>
</body>
(function () {
var app = angular.module('testSortable', ['ui.sortable']);
app.controller('TestSortableController', function ($scope) {
$scope.list1 = [
{
name: "second name",
type: "third type"
}, {
name: "third name",
type: "fourth type"
}
];
$scope.list2 = [
{
name: "another name",
type: "another type"
},{
name: "another second name",
type: "another second type"
},
];
$scope.list1Options = {
placeholder: 'app',
connectWith: '.list_2'
};
$scope.list2Options = {};
});
})();
Answer the question
In order to leave comments, you need to log in
For the first option to work, try
...
<ul id="list_1" class="list_1" ui-sortable="SortCtrl.list1Options" ng-model="list1">
...
<ul id="list_2" class="list_2" ui-sortable="SortCtrl.list2Options" ng-model="list2">
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question