1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > angular使用动态组件后属性值_使用Angular的属性实现具备动态行为的界面组件

angular使用动态组件后属性值_使用Angular的属性实现具备动态行为的界面组件

时间:2022-01-18 01:05:10

相关推荐

angular使用动态组件后属性值_使用Angular的属性实现具备动态行为的界面组件

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

var PageApp = angular.module('angularPageApp', ['ngSanitize']);

PageApp.controller('linkListWidgetCtrl', function($scope) {

// define defaults for the directive behavior in case none are

// provided as html attributes (see directive link function below)

$scope.type = 'row';

$scope.start = 'open';

// content a some ui direction taken from the Google Accounts page (/)

$scope.items = [{

header: {

text: 'Sign-in & security',

css: 'fa-lock',

open: true

},

content: {

title: 'Control your password and account-access settings',

links: ['Signing in to Google', 'Device activity and notifications', 'Connected apps & sites']

}

}, {

header: {

text: 'Personal info and privacy',

css: 'fa-user',

open: true

},

content: {

title: 'Manage your visibility settings and the data we use to personalize your experience.',

links: ['Your personal info', 'Activity control', 'Ads settings', 'Account overview', 'Control your content']

}

}, {

header: {

text: 'Account preferences',

css: 'fa-cog',

open: true

},

content: {

title: 'Set language, accessibility, and other settings that help you use Google.',

links: ['Language & Input Tools', 'Accessibility', 'Your Google Drive storage', 'Delete your account or services']

}

}];

// called once from directive link function if the type is set to 'accordion'

$scope.initAccordion = function() {

$scope.closeAll();

if ($scope.start === 'open') {

$scope.items[0].header.open = true;

}

};

// set the header.open boolean to false for all items

// angular should update the ui for us

$scope.closeAll = function() {

for (var i = 0; i < $scope.items.length; i++) {

$scope.items[i].header.open = false;

}

};

// in none-accordion cases all this does is flip the open boolean for

// the clicked header. if our type is accordion and we're opening a

// currently closed item, we close all items before opening the clicked one

$scope.headerClick = function(header) {

if ($scope.type === 'accordion' && header.open === false) {

$scope.closeAll();

}

header.open = !header.open;

};

});

PageApp.directive('linkListWidget', function($timeout) {

return {

restrict: 'E',

template: [

'

',

'

',

'

',

'',

'',

'{{ item.header.text }}',

'',

'',

'',

'

{{ item.content.title }} ',

'

',

'

{{ link }} ',

'

',

'',

'

',

'

',

'

'

].join(''),

link: function(scope, element, attrs) {

// feed any attributes defined in the html into our controller's scope

if (attrs.type) {

scope.type = attrs.type;

}

if (attrs.start) {

scope.start = attrs.start;

}

if (scope.start === 'close') {

scope.closeAll();

}

if (scope.type === 'accordion') {

scope.initAccordion();

}

}

};

});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。