如何在使用vm = this时调用$ scope。$ broadcast?

时间:2017-01-14 12:28:54

标签: angularjs scope

我用了     var vm = this  相反,在控制器中使用$ scope现在我在编译代码后得到了这个错误。 plzzz告诉我这个问题是什么

//TypeError: Cannot read property '$emit' of undefined

vm.$emit("namePublished", {
       "username": response.user
    });

1 个答案:

答案 0 :(得分:3)

您无法在$scope上调用this方法。所以你需要注入$scope并像往常一样使用。