我正在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)
看起来很复杂,我无法弄清楚逻辑应该注入的位置......
试图在我的 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 后重新启动。
有谁知道问题可能埋在哪里?
今天我想知道在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) 我通过添加链接到它们的源和图层来初始化 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
- 这告诉我实际上需要重新创建这些定义。
有没有一种破坏性较小的方法呢?
我创建了 Angular 应用程序并使用“npm install bootsrap”安装 bootstrap 并将路径添加到 angular.json 文件。但是当我创建一个按钮并添加引导类时,输出不显示应用引导类。
有人可以帮我解决这个问题吗...谢谢
angular ×2
angularjs ×1
codemirror ×1
generator ×1
javascript ×1
mapbox ×1
mapbox-gl-js ×1
offline ×1
typescript ×1
yield ×1