我拼命地尝试将一个简单的字符串传递给AngularJS组件, 我有以下angularJS组件:
异步-typeahead.componenet.js:
angular.module('asyncTypeahead').component('asyncTypeahead', {
templateUrl: 'static/partials/async-typeahead/async-typeahead.template.html',
bindings: {
pk: '=',
object: '=',
objectType: '@'
},
controller: ['$scope','$http',
function AsyncTypeaheadController($scope, $http) {
var self = this;
self.getTags = function (val) {
console.log("async-typeahead input is: " +val);
console.log("async-typeahead object keys are: " + angular.toJson(self.object));
console.log("async-typeahead type is: " + angular.toJson(self.objectType));...
按照html调用组件:
<async-typeahead object="$ctrl.actor.actor_tags" objectType={{ This is just a string }}></async-typeahead>
&#39; VAL&#39;只是输入中的输入。
我已尝试objectType={{ This is just a string }}
和objectType="This is just a string"
以及objectType=This is just a string
我也尝试更改&#39; =&#39;到&#39; @&#39;或者&#39;&gt;&#39;结果是一样的:
每当我看到控制台时,我总能得到:
async-typeahead输入是:df
async-typeahead object kes是:[37,43,49]
async-typeahead类型为: undefined
我做错了什么?如何将简单字符串传递给angularJS组件?
答案 0 :(得分:2)
您在html中使用的objectType属性的问题。指令/组件名称及其所有属性应使用“ - ”分隔。
(function(value){
var names = ["January","February","March","April","May","June","July",
"August","September","October","November","December"];
value.name = function(number){
return names[number];
};
value.number = function(name){
return names.indexOf(name);
};
})(this.month = {});
console.log(month.name(2));
console.log(month.number("November"));