小编use*_*686的帖子

AngularJS:如何使用可选的属性参数编写元素指令?

我正在AngularJS指令中执行我的第一步.只需将此项设置为练习即可输出产品名称:

.directive('productname', function (Prefs) {
        return {
            restrict: 'E',
            replace: true,
            transclude: true,
            templateUrl: '/partials/productname.html',
            link: function (scope, element, attrs) {
                scope.brand = Prefs.owner;
            }
        }
    })
Run Code Online (Sandbox Code Playgroud)

productname.html

<span class="productname"><span class="brand">{{brand}}</span> <span class="product" ng-transclude>{{productname}}</span></span>
Run Code Online (Sandbox Code Playgroud)

这样用法很明显: <productname>{{product.name}}</productname>

现在,有人可以告诉我如何通过添加一个标志来输出链接的productname来使这个指令可配置吗?

用法是:<productname linked>{{product.name}}</productname>输出/模板将是:

<span class="productname"><a href="/edit/{{id}}"> <span class="brand">{{brand}}</span> <span class="product" ng-transclude>{{productname}}</span></a></span>
Run Code Online (Sandbox Code Playgroud)

看起来很复杂,我无法弄清楚逻辑应该注入的位置......

angularjs angularjs-directive

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

无法让 Codemirror HTML 语法高亮显示在 Angular 2 应用程序中工作

试图在我的 angular-cli (Angular 2) 应用程序中使 CodeMirror 的 HTML 突出显示工作(正如我所见,这对某些人来说也是一个问题)。

这是我所拥有的:

应用程序组件.html

<codemirror [(ngModel)]="code" [config]="config"></codemirror>
<div [innerHTML]="code"></div>
Run Code Online (Sandbox Code Playgroud)

app.component.ts

export class AppComponent {
  code = `<p>My HTML</p>\n<!-- hello -->\n<p>Your HTML</p>`;

  config = {
    mode: 'htmlmixed',
    lineWrapping: false,
    lineNumbers: true,
    theme: 'monokai'
  };
}
Run Code Online (Sandbox Code Playgroud)

angular-cli.json (仅列出相关部分)

"addons": [
    "../node_modules/codemirror/mode/xml/xml.js",
    "../node_modules/codemirror/mode/javascript/javascript.js",
    "../node_modules/codemirror/mode/htmlmixed/htmlmixed.js"
],
Run Code Online (Sandbox Code Playgroud)

/ ... /

"styles": [
    "../node_modules/codemirror/lib/codemirror.css",
    "../node_modules/codemirror/theme/monokai.css"
],
Run Code Online (Sandbox Code Playgroud)

app.module.ts

imports: [
    /* ... */
    CodemirrorModule,
],
Run Code Online (Sandbox Code Playgroud)

我尝试了各种将模式作为对象或字符串传递的语法模式,并且 - 如您所见 - 确保首先加载 xml。不行 - 亮点不在那里。我总是确保ng serve在每次编辑 angular-cli.json 后重新启动。

有谁知道问题可能埋在哪里?

codemirror angular

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

如何使用生成器函数实现循环数组

今天我想知道在TypeScript中提供循环数组的最快方法是什么,如:

['one', 'two', 'three'] 
Run Code Online (Sandbox Code Playgroud)

之后的下一个值three将是one,并且我认为它是生成器函数的良好候选者.但它似乎对我不起作用.以下代码有什么问题?

function* stepGen(){
  const steps = ['one', 'two', 'three'];

  let index = 0;

  if(index < steps.length - 1){
   index++;
  } else {
   index = 0;
  }
  yield steps[index];
}

let gen = stepGen();
console.log(gen.next().value); 
console.log(gen.next().value);
console.log(gen.next().value); // should be 'three'
console.log(gen.next().value); // should be 'one'
console.log(gen.next().value);
Run Code Online (Sandbox Code Playgroud)

javascript yield generator typescript

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

有一种干净的方法可以清除地图框要素集合而不丢失图层和源吗?

我通过添加链接到它们的源和图层来初始化 Mapbox 地图。

    mapbox.addSource(MY_SOURCE, {
        'type': 'geojson',
        'data': {
            'type': 'FeatureCollection',
            'features': [],
        },
    });

    mapbox.addLayer({
        'id': MY_LAYER,
        'type': 'circle',
        'source': MY_SOURCE,
        'paint': {
            'circle-radius': 6,
            'circle-color': '#d31467',
        },
    });
Run Code Online (Sandbox Code Playgroud)

我的目标是 - 我希望一次完成这些定义 - 如果我需要更新源代码,我只需:

    mapbox.getSource(MY_SOURCE).setData(geojson);
Run Code Online (Sandbox Code Playgroud)

有时我需要清除所有多边形、所有点、所有东西。我怎样才能做到这一点而不丢失所有这些定义?我只能看到.removeSource, .removeLayer- 这告诉我实际上需要重新创建这些定义。

有没有一种破坏性较小的方法呢?

mapbox mapbox-gl-js

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

如何在 DevTools 中过滤掉齿轮图标 XHR 请求?

是否有负面过滤模式来隐藏此类请求?我的意思不是- 如果它们被发送到多个域,我想一次性过滤它们。

在此处输入图片说明

google-chrome-devtools

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

如何正确地将 bootstrap 添加到 Angular 应用程序

我创建了 Angular 应用程序并使用“npm install bootsrap”安装 bootstrap 并将路径添加到 angular.json 文件。但是当我创建一个按钮并添加引导类时,输出不显示应用引导类。

这是我得到的输出

有人可以帮我解决这个问题吗...谢谢

offline angular

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