【发布时间】: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