0
我是angular
和typescript
的初学者。角度绑定数组和布尔/字符串数据类型
我的打字稿一个模块内的服务看起来像下面
module MyModule {
class HelloService {
public data:string[] = ["1","2","3"];
public booleanvalue:boolean = false;
public stringvalue:string = "hai";
public test() {
this.data.push("hai");
this.booleanvalue = true;
this.stringvalue = "Hai welcome";
}
}
angular.module('MyModule', []).service('hexafy', function() {
return new HelloService();
});
}
我编译上面和injecting
后,在一个HTML文件中添加div元素下获得的JavaScript基准
<div ng-app="myApp" ng-controller="myCtrl">
<br/>
<button ng-click="buttonClick()">Click Me! </button> <br>
<br/>
<label>{{value}}</label><br>
</div>
myCtrl service
hexafy外观如下
var myApp = angular.module('myApp',['MyModule']);
myApp.controller('myCtrl', ['$scope' , 'hexafy' , MyController]);
function MyController($scope, hexafy)
{
var vm = $scope;
vm.thirdpartyfactory = hexafy;
vm.value = vm.thirdpartyfactory.stringvalue;// the problem is in this line
vm.buttonClick = function(){
vm.thirdpartyfactory.test();
}
这是我的问题。 如果我将“数据”绑定到vm.value,它会在按钮单击时更改,但如果我将booleanvalue
或stringvalue
绑定到vm.value,则它不会更新。
什么是这个