Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
Angularjs 角度ng初始未加载_Angularjs - Fatal编程技术网

Angularjs 角度ng初始未加载

Angularjs 角度ng初始未加载,angularjs,Angularjs,所以我使用的是nginit,它正在处理我应用程序的一部分,而不是另一部分 ng init的工作部件 html ng init的非工作部件 html 因此,第一部分工作正常,ng init正在加载,设置sh.editedSchedule.\u id=sh.scheduleProfile.\u id。当我尝试对第二部分执行相同的操作时,ng init没有执行???好的,所以我必须使用$broadcast来初始化函数,仍然可以使用一些调整。所以在不起作用的部分,我就是这么做的 html-我删除了ng

所以我使用的是nginit,它正在处理我应用程序的一部分,而不是另一部分

ng init的工作部件

html

ng init的非工作部件

html


因此,第一部分工作正常,ng init正在加载,设置sh.editedSchedule.\u id=sh.scheduleProfile.\u id。当我尝试对第二部分执行相同的操作时,ng init没有执行???

好的,所以我必须使用$broadcast来初始化函数,仍然可以使用一些调整。所以在不起作用的部分,我就是这么做的

html-我删除了ng init并在下面启动了它

 <input ng-model="cc.editedCourse._id" class="form-control" type="text" name="" readonly="readonly"></input>
  {{ init() }}

{{init()}}
控制器-我设置了一个$broadcast来更改我必须更改的内容,它现在按照我希望的方式工作。欢迎任何建议

$scope.init=()=>{

console.log(“你确定它没有执行吗?或者可能是
cc.courseProfile.\u id
ng init
尝试使用它之前没有分配?是的,它没有执行,我更新了显示角度显示
cc.courseProfile.\u id
。可能是一个时间问题。在你的代码中,你正在设置
courseCtrl.editedCours。”e={};
。可能get是在ng init之后执行的。请尝试在ng init中放置一个console.log,并将其设置为
{}
在控制器中,查看它们的执行顺序。这就是我的想法。此外,正如
ngInit
的文档所述,您可能应该在控制器中分配这些值。我找到了一个解决方法,我将发布答案
    scheduleCtrl.scheduleProfile = {};
    scheduleCtrl.editedSchedule = {};

    scheduleCtrl.updateSchedule = (schedule) => {
        console.log('here is scheduleProfile._id: ', 
      scheduleCtrl.scheduleProfile._id);
        schedulesFactory.update(schedule)
                        .then((r) => {
                          console.log('Updated Schedule!', r);
                          scheduleCtrl.saved = true;
                        })
      }
 <input ng-model="cc.editedCourse._id" class="form-control" type="text" name="" ng-init="cc.editedCourse._id=cc.courseProfile._id" readonly="readonly"></input>
  This works, {{cc.courseProfile._id}}
  courseCtrl.courseProfile = {};
  courseCtrl.editedCourse = {};

         courseCtrl.updateCourse = (course) => {
         console.log('Here is course id: ', courseCtrl.courseProfile._id);
         coursesFactory.update(course)
                       .then((r) => {
                         console.log('course updated: ', r);
                          courseCtrl.saved = true;
                       })
       }
 <input ng-model="cc.editedCourse._id" class="form-control" type="text" name="" readonly="readonly"></input>
  {{ init() }}