【问题标题】:AngularJs 1.6 Component BIndingsAngularJs 1.6 组件绑定
【发布时间】:2017-10-24 12:08:07
【问题描述】:

使用驼峰式绑定路由 angularjs 组件对我不起作用,我不知道为什么。

这是一个例子

组件

angular.
  module('pdaFile').
  component('pdaFile', {
    templateUrl: 'app/myComponent/myComponent.html',
    bindings:{
        data:"<",
        dataFileId:"@",
        datafileid:"@",
        id:"@"
    },
    controller: ['NgTableParams','UserAuthService',
      function pdaFileController(NgTableParams,UserAuthService) {
        var self=this;

...

self.$onInit = function () {
            console.log(self.dataFileId); // undefined
            console.log(self.id); // OK
            console.log(self.datafileid); //OK

        };


appConfig.js

..

// 路由器

angular.
  module('app')
      .config(['$locationProvider', '$routeProvider',
         function config($locationProvider, $routeProvider) {
     $locationProvider.hashPrefix('!');
     $routeProvider.
when('/pda', {
           template: '<pda-file id="pippo" datafileid="current" data-file-id="current"></pda-file>'})
     .  

..

我无法以任何方式填充绑定参数 dataFileId。它总是未定义的。 我试过了

<pda-file data-file-id="current"></pda-file>'

<pda-file dataFileId="current"></pda-file>'

和其他方式。相反,非驼峰式参数 datafileid 和 id 工作正常。

谁能告诉我为什么?

【问题讨论】:

  • 我建议不要使用 data-data 这样的词作为属性名称前缀
  • 你是对的。从 dataFileId 更改为 dtFileId 效果很好,使用 dt-file-id 作为属性

标签: angularjs angularjs-components


【解决方案1】:

你试过了吗?

data-file-id="current"

或者

file-id="current"

然后

bindings:{
    fileId:"@",
}

【讨论】:

  • 是的,我试过了。它适用于 fileId。问题在于使用“数据”作为前缀,这会导致不良行为,正如 Ferie 建议的那样。使用 dtFileId 也可以,并且 dt-file-id 作为标签属性
  • 这样就解决了您的问题?
猜你喜欢
  • 1970-01-01
  • 2018-09-18
  • 1970-01-01
  • 2018-05-01
  • 2017-11-19
  • 2016-12-24
  • 2020-03-21
  • 2017-05-02
  • 2018-03-16
相关资源
最近更新 更多