Javascript 自定义指令模板中的AngularJS控制变量
我做了一个自定义指令, 模板中有一个变量ng model=“test” 在指令控制器中, 如何对变量进行任何更改Javascript 自定义指令模板中的AngularJS控制变量,javascript,angularjs,directive,Javascript,Angularjs,Directive,我做了一个自定义指令, 模板中有一个变量ng model=“test” 在指令控制器中, 如何对变量进行任何更改 angular.module("myDirective", []).directive("ngTest", function(){ return { restrict: "E", scope: true, template: "<input type='text' ng-model='test'>+ <butt
angular.module("myDirective", []).directive("ngTest", function(){
return {
restrict: "E",
scope: true,
template: "<input type='text' ng-model='test'>+
<button ng-click='change()'></button>",
controller: function ($scope, $element){
$scope.change = function(){
// no idea about how to control variable test here.
$scope.test = "123123123"; //this doesn't work. :(
}
}
}
});
angular.module(“myDirective”,[]).directive(“ngTest”,function(){
返回{
限制:“E”,
范围:正确,
模板:“+
",
控制器:函数($scope$element){
$scope.change=函数(){
//不知道如何在这里控制变量测试。
$scope.test=“123123”//这不起作用:(
}
}
}
});
这里是为你工作的地方:)
app.directive(“ngTest”,function()){
返回{
限制:“E”,
范围:正确,
模板:“点击我”,
控制器:函数($scope$element){
$scope.change=函数(){
//不知道如何在这里控制变量测试。
$scope.test=“123123”//这不起作用:(
}
}
}
});
我发现指令中的“+”不起作用,您需要在同一行中提供完整的tempalte,或者使用tempalteUrl为其提供值。很高兴再次帮助您:)
app.directive("ngTest", function(){
return {
restrict: "E",
scope: true,
template: "<input type='text' ng-model='test'><button ng-click='change()'>Click Me</button>",
controller: function ($scope, $element){
$scope.change = function(){
// no idea about how to control variable test here.
$scope.test = "123123123"; //this doesn't work. :(
}
}
}
});