Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $watch在angularjs中没有调用内部选项卡?_Javascript_Angularjs_Angularjs Scope_Angularjs Watch - Fatal编程技术网

Javascript $watch在angularjs中没有调用内部选项卡?

Javascript $watch在angularjs中没有调用内部选项卡?,javascript,angularjs,angularjs-scope,angularjs-watch,Javascript,Angularjs,Angularjs Scope,Angularjs Watch,这是 在我的示例中,我创建了两个输入文本框,一个在选项卡外部,另一个在选项卡内部。对于两者,我创建了一个watch函数。外部的工作正常,但选项卡内部的watch功能不工作。这两个地方都有相同类型的编码,只是我不知道为什么一个在工作,另一个没有 有人能帮我吗 angular.module('components',[])。 指令('tabs',函数(){ 返回{ 限制:'E', 是的, 作用域:{}, 控制器:[“$scope”,函数($scope){ 变量窗格=$scope.panes=[];

这是

在我的示例中,我创建了两个输入文本框,一个在选项卡外部,另一个在选项卡内部。对于两者,我创建了一个watch函数。外部的工作正常,但选项卡内部的watch功能不工作。这两个地方都有相同类型的编码,只是我不知道为什么一个在工作,另一个没有

有人能帮我吗

angular.module('components',[])。
指令('tabs',函数(){
返回{
限制:'E',
是的,
作用域:{},
控制器:[“$scope”,函数($scope){
变量窗格=$scope.panes=[];
$scope.select=函数(窗格){
角度.forEach(窗格、函数(窗格){
pane.selected=false;
});
pane.selected=true;
}
this.addPane=函数(窗格){
如果(panes.length==0)$scope.select(pane);
窗格。推(窗格);
}
}],
模板:
'' +
“
    ”+ “
  • ”+ '' + “
  • ”+ “
”+ '' + '', 替换:正确 }; }). 指令('pane',函数(){ 返回{ 要求:“^tabs”, 限制:'E', 是的, 作用域:{title:'@'}, 链接:函数(范围、元素、属性、tabsCtrl){ tabsCtrl.addPane(范围); }, 模板: '' + '', 替换:正确 }; }) .controller('sample',函数($scope){ $scope.cancel=函数(){ 控制台日志(“取消”) } $scope.$watch('FirstName',function(){ console.log(“名字”) //fetch(); }); $scope.$watch('FirstName1',function(){ console.log(“FirstName1”) //fetch(); }); //在这里,我需要更改所选的选项卡 })

引导选项卡组件
名字
中名
姓
接触
地址1
地址2
电话
可移动的
手机1
这是第四个选项卡的内容。
提交
取消

您应该在ng模型中使用点。参考文献

因此,如果您的代码与以下代码相同,那么您的代码将正常工作:

在javascipt文件中

.controller('sample', function($scope){
    $scope.user = {};
    $scope.cancel = function(){
      console.log("cancel")
    }
    $scope.$watch('user.FirstName', function() {
        console.log("FirstName")
    //  fetch();
    });
    $scope.$watch('FirstName1', function() {
        console.log("FirstName1")
    //  fetch();
    });
      //Here I need to Change Selected Tab
  })
在Html文件中:

<pane id="FirstTab" title="First Tab">
    <div><div class="form-group">
        <label for="text">First Name</label>
        <input type="text" required ng-model="user.FirstName" class="form-control" id="FirstName">
    </div>
        <div class="form-group">
            <label for="text">Middle Name</label>
            <input type="text" required ng-model="user.MiddleName" class="form-control" id="MiddleName">
        </div>
        <div class="form-group">
            <label for="text">Last Name</label>
            <input type="text" required ng-model="user.LastName" class="form-control" id="LastName">
        </div>

    </div>
</pane>

名字
中名
姓

您可以用另一种方式执行此操作。。使用ng也可以改变。。它监视模型中的任何更改,并相应地调用函数。添加这个而不是$watch

 $scope.change = function() {
  console.log("FirstName")
}
在模板中调用ng更改,如下所示

    <input type="text" required ng-model="FirstName" ng-change="change()" class="form-control" id="FirstName">


这是编辑后的plunk的链接

您能在问题中输入代码吗?因为我不会在工作时单击一些随机链接,另外,如果没有足够的代码适合这里,那么您需要首先缩小问题的来源。$scope.$watch('FirstName',function(){console.log(“FirstName”)}$作用域.$watch('FirstName1',function(){console.log(“FirstName1”)});在ng model='FirstName'内部和ng model='FirstName1'外部@Marty我在这里添加了代码。您能检查一下并告诉我哪里出错了吗。
    <input type="text" required ng-model="FirstName" ng-change="change()" class="form-control" id="FirstName">