我试图在指令的链接函数中放置一个Angular Material对话框.从概念上讲,我不明白为什么这是不可能的.根据文档,$mdDialog.show它位于范围上并且$mdDialog.hide();位于由$mdDialog.show对象定义的控制器中.我已经能够将对话框弹出 - 虽然closeModal()执行(我可以通过console.log告诉),但从$mdDialog.hide()不执行,模态永远不会隐藏.
angular.module('app', ['ngMaterial'])
.directive('addLayer', ['$mdDialog', function($mdDialog) {
return {
template: '<h1 ng-click="openDialog()">Open Dialog</h1><div>alert: {{alert}}</div>',
scope: {},
link: function(scope) {
scope.alert = '';
scope.addLayerDialog = function() {
$mdDialog.show({
parent: angular.element(document.body),
templateUrl: {...},
controller: function($scope, $mdDialog) {
$scope.hide = function() {
$mdDialog.hide();
};
$scope.cancel = function() {
$mdDialog.cancel();
};
$scope.answer = function(answer) {
console.log($mdDialog.hide('answer'));
$mdDialog.hide(answer);
};
}
}).then(function(answer) {
scope.alert = 'You said the information was "' …Run Code Online (Sandbox Code Playgroud) javascript angularjs angularjs-directive angularjs-scope angular-material
我一直在寻找使用像SVGO这样的库来清除前端用户提交的SVG代码.SVGO是一个基于node.js的库,它通常在后端工作,所以我一直在努力探索如何从前端到后端发送SVG代码然后让清理后的代码重新启动前端.
当我试图解决这个问题时,我检查了他们的网络应用程序示例,经过检查,在链接脚本中运行代码,我通常会在前端的后端看到这些代码.特别是,他们的许多功能都有签名(完整脚本):
1: [function(require, module, exports) {
"use strict";
var loadScripts = require("./load-scripts"),
...
module.exports = exportedFunction;
}]
Run Code Online (Sandbox Code Playgroud)
非常令人迷惑,因为这是典型的JS,我已经与后端,特别是相关的require,module.exports语法仅举几例.
题
感谢您的任何见解.我正在努力确保以最符合Web标准的方式构建我的项目.
我有一个父州和一个子州.父状态解析一个对象.然后,子状态从父状态解析该对象.
因为子状态是从父状态解析对象,所以我希望发生双向绑定.奇怪的是,虽然从子状态改变(即添加属性),更新父状态中的对象 - 父状态中对象的更改不会影响子状态中的已解析对象,这让我感到惊讶.
我知道我可以$broadcast将父状态中已解析的对象更改为子状态,但我想了解为什么子状态中的已解析对象未自动更新.
这是我正在使用的.家长州:
.config(function($stateProvider) {
$stateProvider.state('parent', {
template: ''
+' <div>Parent State</div>'
+' <div>Modify property on parent state, object.someProperty:'
+' <input ng-model="object.someProperty">'
+' {{object.someProperty}}'
+' </div>'
+' </div>'
+' Include Child State'
+' <ui-view></ui-view>',
controller: function($scope) {
$scope.object = object;
},
resolve: {
object: [function() {
var object = '';
object.someProperty = 'initialValue';
return object;
}]
}
})
Run Code Online (Sandbox Code Playgroud)
和孩子状态:
.state('parent.child', {
template: ''
+' <div>Child State</div>'
+' <div>Watch property from parent state, object.someProperty'
+' {{object.someProperty}}' …Run Code Online (Sandbox Code Playgroud) 从文档中,Angular Material中的对话框具有如下签名:
function showAlert() {
alert = $mdDialog.alert()
.title('Attention, ' + $scope.userName)
.content('This is an example of how easy dialogs can be!')
.ok('Close');
$mdDialog
.show( alert )
.finally(function() {
alert = undefined;
});
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法找到任何文档.finally.它似乎是我可以收集的回调函数,尽管文档奇怪地缺少任何信息.
我应该假设它是一个正常的回调函数 - 为什么它上面的文档缺乏 - 这就是这种简单的标准指令语法,这被认为是处理回调的方式,比如.then?
感谢您提供任何信息.
我希望能够访问我的run函数中的url参数,并根据这些参数进行操作.但是,我很惊讶地看到ui.router的$stateParams对象在我的run函数中是空的.
angular.module('app', ['ui.router'])
.run(['$rootScope', '$state', '$stateParams', '$location', function($rootScope, $state, $stateParams, $location) {
$rootScope.$state = $state;
$rootScope.location = $location;
$rootScope.$stateParams = $stateParams;
$rootScope.$on('$stateChangeStart', function(event, toState) {
if (toState.name === 'main') {
event.preventDefault();
$state.go('main.child', {
param: 1
})
}
});
console.log('$stateParams is empty!');
console.log($stateParams);
console.log($rootScope.$stateParams);
}])
.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function($stateProvider, $urlRouterProvider, $locationProvider) {
$stateProvider
.state('main', {
url: '',
template: '<div>hey</div><div ui-view></div>'
})
.state('main.child', {
url: '/:param',
template: 'child state template'
});
}]);
Run Code Online (Sandbox Code Playgroud)
是否可以访问从$stateParamsrun函数中访问的params ?或者它们仅在config功能中可用?为什么 …
我正在浏览Angular2指南,虽然关键字implements在类定义中使用,但在文档中并没有真正详细描述.
例如,在以下内容中:
export class CrisisDetailComponent implements OnInit, CanDeactivate {
crisis: Crisis;
editName: string;
cancel() {
this.editName = this.crisis.name;
this.gotoCrises();
}
save() {
this.crisis.name = this.editName;
this.gotoCrises();
}
}
Run Code Online (Sandbox Code Playgroud)
OnInit通过implements关键字引入类,但我最常见的是OnInit导入import {Component, OnInit} from 'angular2/core',然后在类定义中使用.
implements关键字的效用是什么?而且,OnInit这个类定义中没有直接使用,那为什么它会被带入课堂呢?为implements使OnInit可用的goToCrises()方法?如果是这样,为什么你不能只注入OnInit定义的组件goToCrises()?
谢谢你的帮助.