首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NG2-在角2 btnRadio种子项目中引导rc2。ngModel的双向绑定被破坏了吗?

NG2-在角2 btnRadio种子项目中引导rc2。ngModel的双向绑定被破坏了吗?
EN

Stack Overflow用户
提问于 2016-06-20 21:59:00
回答 2查看 987关注 0票数 2

我试图在角2 rc2种子项目中使用NG2引导单选按钮。下面的代码在我们的Range2 rc1项目中没有任何问题。现在,我正在尝试创建一个使用https://github.com/mgechev/angular2-seed作为基础的种子项目,但无法正确地完成。

我以以下方式使用NG2-引导单选按钮指令:

代码语言:javascript
复制
<div class="btn btn-primary" [(ngModel)]="mode" btnRadio="EDITOR" uncheckable> 
     Editor 
</div>

我在seed.config.ts.中包括了ng2引导程序和矩库。我尝试了许多变体(也与ng2-bootstrap/ng2-bootstrap等)。

代码语言:javascript
复制
paths: {
  ...
  'ng2-bootstrap': `${this.NPM_BASE}/ng2-bootstrap/`,
  'moment': `${this.NPM_BASE}moment/`
},
packages: {
    ...
    'ng2-bootstrap': { main: "ng2-bootstrap.js", defaultExtension: 'js' },
    'moment': { main: "moment.js", defaultExtension: 'js' },
}

我导入以下指令

代码语言:javascript
复制
import { BUTTON_DIRECTIVES } from 'ng2-bootstrap/ng2-bootstrap';
import { ButtonRadioDirective } from 'ng2-bootstrap/ng2-bootstrap';

并按我的组件使用这个

代码语言:javascript
复制
@Component({
  moduleId: module.id,
  selector: "editor",
  templateUrl: "editor.html",
  directives: [FORM_DIRECTIVES, CORE_DIRECTIVES, BUTTON_DIRECTIVES, 
  CodeMirrorComponent, ButtonRadioDirective]
})

我构建该项目时没有出现任何问题,但是当我运行服务器时,我会获得以下运行时异常:

代码语言:javascript
复制
ORIGINAL EXCEPTION: No value accessor for ''

我敢肯定,ngModel的双向绑定在这里被打破了.我在rc1捆绑包和没有种子项目时使用了这段代码。现在我不确定是什么问题-新的角度版本,或使用一个构建系统(在我的例子-吞咽)。

我希望任何人都能帮上忙。在此之前,非常感谢您。

编辑自2016年6月21.06.2016

使用过的软件包的版本如下:

代码语言:javascript
复制
"dependencies": {
  "@angular/common": "2.0.0-rc.2",
  "@angular/compiler": "2.0.0-rc.2",
  "@angular/core": "2.0.0-rc.2",
  "@angular/forms": "^0.1.0",
  "@angular/platform-browser": "2.0.0-rc.2",
  "@angular/platform-browser-dynamic": "2.0.0-rc.2",
  "@angular/router": "3.0.0-alpha.6",
  "es6-module-loader": "^0.17.8",
  "core-js": "^2.4.0",
  "rxjs": "5.0.0-beta.6",
  "systemjs": "0.19.26",
  "zone.js": "^0.6.12",
  "bootstrap": "^3.3.6",
  "ng2-bootstrap": "^1.0.17"
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-06-21 21:20:18

谢谢大家,我找到了问题和(暂时)解决办法。问题是ng2-bootstrapangular.forms之间的冲突(我的版本是0.1.0)。这个问题与这个问题有关,https://github.com/valor-software/ng2-bootstrap/issues/627

我现在不使用角形式,在main.ts中有简单的注释行

代码语言:javascript
复制
//import { disableDeprecatedForms, provideForms } from '@angular/forms/index';

bootstrap(AppComponent, [
   //disableDeprecatedForms(),
   //provideForms(),
   APP_ROUTER_PROVIDERS,
   {
      provide: APP_BASE_HREF,
      useValue: '<%= APP_BASE %>'
   }
]);

我的代码现在正常工作了。

票数 1
EN

Stack Overflow用户

发布于 2016-06-21 11:23:55

下列措施应能发挥作用:

导入

代码语言:javascript
复制
import {AlertComponent} from 'ng2-bootstrap/ng2-bootstrap';

路径

代码语言:javascript
复制
'ng2-bootstrap': `${this.NPM_BASE}ng2-bootstrap/bundles/ng2-bootstrap.js`,
'moment/*': `${this.NPM_BASE}moment/*`,

代码语言:javascript
复制
'ng2-bootstrap': {defaultExtension: 'js'},
moment: { main: 'moment.js', defaultExtension: 'js' }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37932493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档