我是 AngularJs 的新手,在下面的代码中遇到了麻烦。
return {
require: ['^myElement'],
restrict: 'EA',
replace: true,
scope: true,
link: function (scope, element, attrs, ctrls) {
scope.xa = 'This is xa'
scope.$on('form:submit', function() {
scope.xb = 'This is xb'
var data = $compile( '<p>{{xa}} {{xb}}</p>' )( scope );
console.log(data.html()); //result is '{{xa}} {{xb}}', the expressions were not applied
});
}
}
我从日志中得到的输出是'{{xa}} {{xb}}'
,它应该是
'This is xa This is xb'