小编Edu*_*nal的帖子

具有特定类型的通用指令(UI组件继承)

我正在开发一个项目来呈现HTML,将特殊的XML作为输入.我已经成功完成了基本案例.例如:

<mybutton name="layla"></mybutton>
Run Code Online (Sandbox Code Playgroud)

转换为

<div class="btn">Layla</div>
Run Code Online (Sandbox Code Playgroud)

使用像这样的指令

.directive('mybutton', function() {
    return {
        restrict: 'E',
        scope: {
            name: '@'
        },
        templateUrl: 'uicomponents/uiButton.html'
    }
})
Run Code Online (Sandbox Code Playgroud)

我将收到的真正的XML输入是:

<ui type="back_button" x="10.0" y="630.0"/>
Run Code Online (Sandbox Code Playgroud)

我想避免更改XML语法,但必要时可以完成.所有屏幕组件都在<ui></ui>标签中.该type属性定义组件.

你会如何为这种标签写出指令?为<ui>元素创建一个巨大的指令并且在属性内部有一个长的switch-case 似乎并不聪明.

angularjs angularjs-directive

2
推荐指数
1
解决办法
3042
查看次数

AngularJS - 指令中的不同模板

我有一个基于twitter bootstrap的表单,每个字段都有自己的配置

// controller (the template shows this in ng-repeat

$scope.fields = [{name:"f1", label:"Field 1", with_button: false},
                 {name:"f2", label:"Field 2", with_button: true}]
Run Code Online (Sandbox Code Playgroud)

我正在尝试制作一个"条件指令",根据"field.with_button"自定义模板

// Without button
<div class="controls">
    <input type="text" id="i_{{field.name}}">
</div>

// With button
<div class="controls">
    <div class="input-append">
        <input type="text" id="i_{{field.name}}">
        <span class="add-on">bt</span>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我搜索了很多,没有找到任何解决方案,我试图只创建一个div并将内容放入编译器函数但它没有解析,如果我称之为$apply崩溃.

我怎么能做这个指令?

错了我上次尝试:

angular.module('mymodule',[]).directive('ssField', function() {
    return {
        transclude:false,
        scope: {
            field: '='
        },
        restrict: 'E',
        replace:true,
        template: '<div class="controls">{{innerContent}}</div>',
        controller: ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
            $scope.$eval('$scope.innerContent = \'<input …
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-directive angularjs-ng-repeat

2
推荐指数
1
解决办法
5184
查看次数

Boto - AWS SNS如何提取主题的ARN号码

创建AWS SNS主题时:

a = conn.create_topic(topicname)
Run Code Online (Sandbox Code Playgroud)

或者已经创建了主题:

a = conn.get_all_topics()
Run Code Online (Sandbox Code Playgroud)

结果是:

{u'CreateTopicResponse': {u'ResponseMetadata': {u'RequestId': u'42b46710-degf-52e6-7d86-2ahc8e1c738c'}, u'CreateTopicResult': {u'TopicArn': u'arn:aws:sns:eu-west-1:467741034465:exampletopic'}}}
Run Code Online (Sandbox Code Playgroud)

问题是如何将主题的ARN作为字符串:arn:aws:sns:eu-west-1:467741034465:exampletopic

python boto amazon-web-services amazon-sns

2
推荐指数
1
解决办法
4121
查看次数

在指令中获取子属性

特定

<mytag class="red">
     <mysubtag id="3"></mysubtag>
</mysubtag> 
Run Code Online (Sandbox Code Playgroud)

子标签可能具有不同的含义,具体取决于父标签(可能是mytag或mysupercustomtag).我有所有父标签的指令.我如何访问子标签?

我知道在mytag我可以使用该指令的链接功能children(),contents()以及data(),甚至elm.find('#someid').像下面这样的东西可以做到吗?这样做的正确方法是什么?嵌套指令?

.directive('mytag', function() {
  return {
    restrict: 'A',
    template: '<div></div>',
    replace: true,
    link: function (scope, element, attrs) {
        // get the id of the first child (for example mysubtag)
        var newid = element.children()[0].getAttribute('id');
        // and put it in mytag, so that it is transformed into <div class="red" id="3">..
        attrs.$set('id', newid);
    }
  } 
})
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-directive

1
推荐指数
1
解决办法
5156
查看次数