Use $scope instead of scope in directives

This commit is contained in:
Blade Barringer
2015-08-22 16:59:35 -05:00
parent 5e510aade0
commit 6b7ca3e823
8 changed files with 23 additions and 22 deletions

View File

@@ -9,10 +9,10 @@
function closeMenu() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
link: function($scope, element, attrs) {
element.on('click', function(event) {
scope._expandedMenu = null;
scope.$apply()
$scope._expandedMenu = null;
$scope.$apply()
});
}
}

View File

@@ -1,5 +1,6 @@
'use strict';
var count = 0;
(function(){
angular
@@ -9,10 +10,10 @@
function expandMenu() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
link: function($scope, element, attrs) {
element.on('click', function(event) {
scope._expandedMenu = (scope._expandedMenu == attrs.menu) ? null : attrs.menu;
scope.$apply()
$scope._expandedMenu = ($scope._expandedMenu === attrs.menu) ? null : attrs.menu;
$scope.$apply()
});
}
}

View File

@@ -12,9 +12,9 @@
function focusMe($timeout, $parse) {
return {
link: function(scope, element, attrs) {
link: function($scope, element, attrs) {
var model = $parse(attrs.focusMe);
scope.$watch(model, function(value) {
$scope.$watch(model, function(value) {
$timeout(function() {
element[0].focus();
});

View File

@@ -11,18 +11,18 @@
];
function fromNow($interval, $timeout) {
return function(scope, element, attr){
return function($scope, element, attr){
var interval, timeout;
var updateText = function(){
element.text(moment(scope.message.timestamp).fromNow());
element.text(moment($scope.message.timestamp).fromNow());
};
var setupInterval = function() {
if(interval) $interval.cancel(interval);
if(timeout) $timeout.cancel(timeout);
var diff = moment().diff(scope.message.timestamp, 'minute');
var diff = moment().diff($scope.message.timestamp, 'minute');
if(diff < 60) {
// Update every minute
@@ -37,7 +37,7 @@
updateText();
setupInterval();
scope.$on('$destroy', function() {
$scope.$on('$destroy', function() {
if(interval) $interval.cancel(interval);
if(timeout) $timeout.cancel(timeout);
});

View File

@@ -19,10 +19,10 @@
// main: '@', // true if it's the user's main list
// obj: '='
//},
link: function(scope, element, attrs) {
link: function($scope, element, attrs) {
// $scope.obj needs to come from controllers, so we can pass by ref
scope.main = attrs.main;
scope.modal = attrs.modal;
$scope.main = attrs.main;
$scope.modal = attrs.modal;
var dailiesView;
if(User.user.preferences.dailyDueDefaultView) {
dailiesView = "remaining";

View File

@@ -15,9 +15,9 @@
restrict: 'EA',
replace: true,
scope: { title: '@', content: '@', placement: '@', animation: '&', isOpen: '&' },
link: function(scope, element, attrs) {
scope.$watch('content', function(value, oldValue) {
scope.unsafeContent = $sce.trustAsHtml(scope.content);
link: function($scope, element, attrs) {
$scope.$watch('content', function(value, oldValue) {
$scope.unsafeContent = $sce.trustAsHtml($scope.content);
});
},
templateUrl: 'template/popover/popover-html.html'

View File

@@ -13,8 +13,8 @@
*/
function taskFocus($timeout) {
return function(scope, elem, attrs) {
scope.$watch(attrs.taskFocus, function(newVal) {
return function($scope, elem, attrs) {
$scope.$watch(attrs.taskFocus, function(newVal) {
if (newVal) {
$timeout(function() {
elem[0].focus();

View File

@@ -6,12 +6,12 @@
.directive('whenScrolled', whenScrolled);
function whenScrolled() {
return function(scope, elm, attr) {
return function($scope, elm, attr) {
var raw = elm[0];
elm.bind('scroll', function() {
if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
scope.$apply(attr.whenScrolled);
$scope.$apply(attr.whenScrolled);
}
});
};