我处于一种奇怪的情况,我需要为选定的角度元素创建一个动态视图模型。为类似的角度对象动态创建视图模型
考虑我在我的html视图中有三个不同的指令,名为<paragragh>
,它们都连接到单个控制器,ParagraphController
。由于我需要在它们之间共享设置,因此我定义了一项服务来保存名为ParagraphConfig
的共享变量,该变量连接到名为ParagraphConfigConroller
的控制器。
paragraph.config.js
(function() {
'use strict'
angular
.module('Application')
.directive('ParagraphConfig', ParagraphConfigService);
function ParagraphConfigService() {
var paragraph = {
text: 'blah blah',
style: {
fontWeight: 'normal',
border: 0
}
}
return {
get: get
}
function get() {
return paragraph;
}
}
})();
config.controller.js
- >controllerAs: ParagraphConfigViewModel
(function() {
'use strict'
angular
.module('Application')
.directive('ParagraphConfigController', ParagraphConfigController);
function ParagraphConfigController(ParagraphConfig.get) {
var self = this;
self.paragraph = ParagraphConfig.get();
}
})();
paragraph.directive.js
(function() {
'use strict'
angular
.module('Application')
.directive('paragraph', ParagraphDirective);
function ParagraphDirective() {
return {
restrict: 'E',
templateUrl: '/path/to/templates/paragraph.html',
scope: true,
replace: true,
require: '^component',
controller: 'ParagraphController',
controllerAs: 'ParagraphViewModel'
}
}
})();
paragraph.controller.js
- >controllerAs: ParagraphViewModel
(function() {
'use strict'
angular
.module('Application')
.directive('ParagraphController', ParagraphController);
function ParagraphController(ParagraphConfig.get) {
var self = this;
self.paragraph = ParagraphConfig.get();
}
})();
其实我使用ParagraphConfig
来分享/更改每个段落的设置。以下是我如何将设置绑定到每个p
标签。
我有一个paragraph.html
和config.html
如下。
paragraph.html
<p ng-style="ParaghViewModel.paragraph.style">
{{ParagraphViewModel.paragraph.text}}
</p>
config.html
<input type="radio" name="font weight"
ng-model="ParagraphViewModel.fontWeight" value="bold"> Bold
<input type="radio" name="font weight"
ng-model="ParagraphViewModel.fontWeight" value="normal"> Normal
现在的问题是,当我选择一个段落(我将通过点击每个段落被激活的设置面板中),并尝试改变其设置,它会影响其他段落。
是否有任何解决方案通过点击每个段落创建一个独特的视图模型?
简单,使用C++,并按照该代码https://stackoverflow.com/questions/39423549/confusing-random-compilation-error然后,您需要使用C+++++中包含的o5t.exe文件编译md5哈希,然后将md5哈希路由重新路由到oc3光纤线路,同时这样做,为osb4h重新构建b5桥接器, -protetecter。确保包含#include否则没有工作:/ –
@ teammolotov.pro我在说'angularjs',你给我一个'C++'的例子! – sadrzadehsina